hast-util-to-dom
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -7,9 +7,11 @@ 'use strict'; | ||
const ROOT_NODE = 'root'; | ||
const TEXT_NODE = 'text'; | ||
const ELEMENT_NODE = 'element'; | ||
const DOCUMENT_TYPE_NODE = 'doctype'; | ||
const COMMENT_NODE = 'comment'; | ||
var ROOT_NODE = 'root'; | ||
var TEXT_NODE = 'text'; | ||
var ELEMENT_NODE = 'element'; | ||
var DOCUMENT_TYPE_NODE = 'doctype'; | ||
var COMMENT_NODE = 'comment'; | ||
function transform(node, options = {}) { | ||
function transform(node) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
switch (node.type) { | ||
@@ -34,20 +36,21 @@ case ROOT_NODE: | ||
*/ | ||
function root(node, options = {}) { | ||
const { | ||
fragment, | ||
namespace: optionsNamespace | ||
} = options; | ||
const { children = [] } = node; | ||
const { length: childrenLength } = children; | ||
function root(node) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var fragment = options.fragment, | ||
optionsNamespace = options.namespace; | ||
var _node$children = node.children, | ||
children = _node$children === undefined ? [] : _node$children; | ||
var childrenLength = children.length; | ||
let namespace = optionsNamespace; | ||
let rootIsDocument = childrenLength === 0; | ||
for (let i = 0; i < childrenLength; i += 1) { | ||
const { | ||
tagName, | ||
properties: { | ||
xmlns | ||
} = {} | ||
} = children[i]; | ||
var namespace = optionsNamespace; | ||
var rootIsDocument = childrenLength === 0; | ||
for (var i = 0; i < childrenLength; i += 1) { | ||
var _children$i = children[i], | ||
tagName = _children$i.tagName, | ||
_children$i$propertie = _children$i.properties; | ||
_children$i$propertie = _children$i$propertie === undefined ? {} : _children$i$propertie; | ||
var xmlns = _children$i$propertie.xmlns; | ||
if (tagName === 'html') { | ||
@@ -68,3 +71,3 @@ // If we have a root HTML node, we don't need to render as a fragment | ||
// The root node will be a Document, DocumentFragment, or HTMLElement | ||
let el; | ||
var el = void 0; | ||
if (rootIsDocument) { | ||
@@ -79,5 +82,5 @@ el = document.implementation.createDocument(namespace, '', null); | ||
// Transform children | ||
const childOptions = Object.assign({ fragment, namespace }, options); | ||
for (let i = 0; i < childrenLength; i += 1) { | ||
const childEl = transform(children[i], childOptions); | ||
var childOptions = Object.assign({ fragment: fragment, namespace: namespace }, options); | ||
for (var _i = 0; _i < childrenLength; _i += 1) { | ||
var childEl = transform(children[_i], childOptions); | ||
if (childEl) { | ||
@@ -115,29 +118,44 @@ el.appendChild(childEl); | ||
*/ | ||
function element(node, options = {}) { | ||
const { namespace } = options; | ||
const { tagName, properties, children = [] } = node; | ||
const el = typeof namespace !== 'undefined' ? document.createElementNS(namespace, tagName) : document.createElement(tagName); | ||
function element(node) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var namespace = options.namespace; | ||
var tagName = node.tagName, | ||
properties = node.properties, | ||
_node$children2 = node.children, | ||
children = _node$children2 === undefined ? [] : _node$children2; | ||
var el = typeof namespace !== 'undefined' ? document.createElementNS(namespace, tagName) : document.createElement(tagName); | ||
// Add HTML attributes | ||
const props = Object.keys(properties); | ||
const { length } = props; | ||
for (let i = 0; i < length; i += 1) { | ||
const key = props[i]; | ||
const info = information(key) || { | ||
var props = Object.keys(properties); | ||
var length = props.length; | ||
for (var i = 0; i < length; i += 1) { | ||
var key = props[i]; | ||
var info = information(key) || { | ||
name: key, | ||
propertyName: key | ||
}; | ||
const { | ||
name, | ||
propertyName, | ||
mustUseAttribute, | ||
mustUseProperty, | ||
boolean, | ||
overloadedBoolean | ||
// numeric, | ||
// positiveNumeric, | ||
// commaSeparated, | ||
// spaceSeparated, | ||
} = info; | ||
const value = properties[key]; | ||
var name = info.name, | ||
propertyName = info.propertyName, | ||
mustUseAttribute = info.mustUseAttribute, | ||
mustUseProperty = info.mustUseProperty, | ||
boolean = info.boolean, | ||
overloadedBoolean = info.overloadedBoolean, | ||
commaSeparated = info.commaSeparated, | ||
spaceSeparated = info.spaceSeparated; | ||
var value = properties[key]; | ||
if (Array.isArray(value)) { | ||
if (commaSeparated) { | ||
value = value.join(', '); | ||
} else if (spaceSeparated) { | ||
value = value.join(' '); | ||
} else { | ||
value = value.join(' '); | ||
} | ||
} | ||
try { | ||
@@ -165,5 +183,6 @@ if (mustUseProperty) { | ||
// Transform children | ||
const { length: childrenLength } = children; | ||
for (let i = 0; i < childrenLength; i += 1) { | ||
const childEl = transform(children[i], options); | ||
var childrenLength = children.length; | ||
for (var _i2 = 0; _i2 < childrenLength; _i2 += 1) { | ||
var childEl = transform(children[_i2], options); | ||
if (childEl) { | ||
@@ -177,3 +196,5 @@ el.appendChild(childEl); | ||
function toDOM(hast, options = {}) { | ||
function toDOM(hast) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return transform(hast, options); | ||
@@ -180,0 +201,0 @@ } |
{ | ||
"name": "hast-util-to-dom", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Transform HAST to DOM", | ||
@@ -5,0 +5,0 @@ "main": "dist/hast-util-to-dom.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14731
330