mdast-util-to-hast
Advanced tools
Comparing version 3.0.4 to 4.0.0
@@ -15,2 +15,5 @@ 'use strict' | ||
var def | ||
var backReference | ||
var content | ||
var tail | ||
@@ -23,12 +26,22 @@ if (!length) { | ||
def = footnotes[index] | ||
content = def.children.concat() | ||
tail = content[content.length - 1] | ||
backReference = { | ||
type: 'link', | ||
url: '#fnref-' + def.identifier, | ||
data: {hProperties: {className: ['footnote-backref']}}, | ||
children: [{type: 'text', value: '↩'}] | ||
} | ||
if (!tail || tail.type !== 'paragraph') { | ||
tail = {type: 'paragraph', children: []} | ||
content.push(tail) | ||
} | ||
tail.children.push(backReference) | ||
listItems[index] = { | ||
type: 'listItem', | ||
data: {hProperties: {id: 'fn-' + def.identifier}}, | ||
children: def.children.concat({ | ||
type: 'link', | ||
url: '#fnref-' + def.identifier, | ||
data: {hProperties: {className: ['footnote-backref']}}, | ||
children: [{type: 'text', value: '↩'}] | ||
}), | ||
children: content, | ||
position: def.position | ||
@@ -45,7 +58,3 @@ } | ||
thematicBreak(h), | ||
list(h, { | ||
type: 'list', | ||
ordered: true, | ||
children: listItems | ||
}) | ||
list(h, {type: 'list', ordered: true, children: listItems}) | ||
], | ||
@@ -52,0 +61,0 @@ true |
@@ -12,23 +12,36 @@ 'use strict' | ||
var head = children[0] | ||
var raw = all(h, node) | ||
var loose = parent ? listLoose(parent) : listItemLoose(node) | ||
var props = {} | ||
var single = false | ||
var result | ||
var container | ||
var index | ||
var length | ||
var child | ||
if ( | ||
(!parent || !parent.loose) && | ||
children.length === 1 && | ||
head.type === 'paragraph' | ||
) { | ||
single = true | ||
/* Tight lists should not render 'paragraph' nodes as 'p' tags */ | ||
if (loose) { | ||
result = raw | ||
} else { | ||
result = [] | ||
length = raw.length | ||
index = -1 | ||
while (++index < length) { | ||
child = raw[index] | ||
if (child.tagName === 'p') { | ||
result = result.concat(child.children) | ||
} else { | ||
result.push(child) | ||
} | ||
} | ||
} | ||
result = all(h, single ? head : node) | ||
if (typeof node.checked === 'boolean') { | ||
if (!single && (!head || head.type !== 'paragraph')) { | ||
if (loose && (!head || head.type !== 'paragraph')) { | ||
result.unshift(h(null, 'p', [])) | ||
} | ||
container = single ? result : result[0].children | ||
container = loose ? result[0].children : result | ||
@@ -51,3 +64,3 @@ if (container.length !== 0) { | ||
if (!single && result.length !== 0) { | ||
if (loose && result.length !== 0) { | ||
result = wrap(result, true) | ||
@@ -58,1 +71,22 @@ } | ||
} | ||
function listLoose(node) { | ||
var loose = node.spread | ||
var children = node.children | ||
var length = children.length | ||
var index = -1 | ||
while (!loose && ++index < length) { | ||
loose = listItemLoose(children[index]) | ||
} | ||
return loose | ||
} | ||
function listItemLoose(node) { | ||
var spread = node.spread | ||
return spread === undefined || spread === null | ||
? node.children.length > 1 | ||
: spread | ||
} |
@@ -19,3 +19,3 @@ 'use strict' | ||
} else if (subtype === 'full') { | ||
suffix += '[' + node.identifier + ']' | ||
suffix += '[' + (node.label || node.identifier) + ']' | ||
} | ||
@@ -22,0 +22,0 @@ |
{ | ||
"name": "mdast-util-to-hast", | ||
"version": "3.0.4", | ||
"version": "4.0.0", | ||
"description": "Transform mdast to hast", | ||
@@ -53,2 +53,8 @@ "license": "MIT", | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -55,0 +61,0 @@ "tabWidth": 2, |
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
25225
597