turndown
Advanced tools
Comparing version 4.0.0-rc.3 to 4.0.0
@@ -18,13 +18,29 @@ var TurndownService = (function () { | ||
var blockElements = [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
]; | ||
function isBlock (node) { | ||
return [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
]; | ||
function isVoid (node) { | ||
return voidElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
} | ||
var rules = {}; | ||
@@ -224,2 +240,3 @@ | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.emDelimiter + content + options.emDelimiter | ||
@@ -233,2 +250,3 @@ } | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.strongDelimiter + content + options.strongDelimiter | ||
@@ -247,2 +265,4 @@ } | ||
replacement: function (content) { | ||
if (!content.trim()) return '' | ||
var delimiter = '`'; | ||
@@ -356,134 +376,16 @@ var leadingSpace = ''; | ||
/** | ||
* This file automatically generated from `pre-publish.js`. | ||
* Do not manually edit. | ||
*/ | ||
var voidElements = { | ||
"area": true, | ||
"base": true, | ||
"br": true, | ||
"col": true, | ||
"embed": true, | ||
"hr": true, | ||
"img": true, | ||
"input": true, | ||
"keygen": true, | ||
"link": true, | ||
"menuitem": true, | ||
"meta": true, | ||
"param": true, | ||
"source": true, | ||
"track": true, | ||
"wbr": true | ||
}; | ||
/** | ||
* This file automatically generated from `build.js`. | ||
* Do not manually edit. | ||
*/ | ||
var blockElements$1 = [ | ||
"address", | ||
"article", | ||
"aside", | ||
"blockquote", | ||
"canvas", | ||
"dd", | ||
"div", | ||
"dl", | ||
"dt", | ||
"fieldset", | ||
"figcaption", | ||
"figure", | ||
"footer", | ||
"form", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6", | ||
"header", | ||
"hgroup", | ||
"hr", | ||
"li", | ||
"main", | ||
"nav", | ||
"noscript", | ||
"ol", | ||
"output", | ||
"p", | ||
"pre", | ||
"section", | ||
"table", | ||
"tfoot", | ||
"ul", | ||
"video" | ||
]; | ||
'use strict'; | ||
Object.keys(voidElements).forEach(function (name) { | ||
voidElements[name.toUpperCase()] = 1; | ||
}); | ||
var blockElements = {}; | ||
blockElements$1.forEach(function (name) { | ||
blockElements[name.toUpperCase()] = 1; | ||
}); | ||
/** | ||
* isBlockElem(node) determines if the given node is a block element. | ||
* collapseWhitespace(options) removes extraneous whitespace from an the given element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
* @param {Object} options | ||
*/ | ||
function isBlockElem(node) { | ||
return !!(node && blockElements[node.nodeName]); | ||
} | ||
function collapseWhitespace (options) { | ||
var element = options.element; | ||
var isBlock = options.isBlock; | ||
var isVoid = options.isVoid; | ||
var isPre = options.isPre || function (node) { | ||
return node.nodeName === 'PRE' | ||
}; | ||
/** | ||
* isPreElem(node) determines if the given node is a PRE element. | ||
* | ||
* Whitespace for PRE elements are not collapsed. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isPreElem(node) { | ||
return node.nodeName === 'PRE'; | ||
} | ||
if (!element.firstChild || isPre(element)) return | ||
/** | ||
* isVoid(node) determines if the given node is a void element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isVoid(node) { | ||
return !!(node && voidElements[node.nodeName]); | ||
} | ||
/** | ||
* whitespace(elem [, isBlock]) removes extraneous whitespace from an | ||
* the given element. The function isBlock may optionally be passed in | ||
* to determine whether or not an element is a block element; if none | ||
* is provided, defaults to using the list of block elements provided | ||
* by the `block-elements` module. | ||
* | ||
* @param {Node} elem | ||
* @param {Function} blockTest | ||
*/ | ||
function collapseWhitespace(elem, isBlock, isPre) { | ||
if (!elem.firstChild || elem.nodeName === 'PRE') return; | ||
if (typeof isBlock !== 'function') { | ||
isBlock = isBlockElem; | ||
} | ||
if (typeof isPre !== 'function') { | ||
isPre = isPreElem; | ||
} | ||
var prevText = null; | ||
@@ -493,10 +395,10 @@ var prevVoid = false; | ||
var prev = null; | ||
var node = next(prev, elem, isPre); | ||
var node = next(prev, element, isPre); | ||
while (node !== elem) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { | ||
// Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
while (node !== element) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { // Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
var text = node.data.replace(/[ \r\n\t]+/g, ' '); | ||
if ((!prevText || / $/.test(prevText.data)) && !prevVoid && text[0] === ' ') { | ||
if ((!prevText || / $/.test(prevText.data)) && | ||
!prevVoid && text[0] === ' ') { | ||
text = text.substr(1); | ||
@@ -508,3 +410,3 @@ } | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -515,4 +417,3 @@ | ||
prevText = node; | ||
} else if (node.nodeType === 1) { | ||
// Node.ELEMENT_NODE | ||
} else if (node.nodeType === 1) { // Node.ELEMENT_NODE | ||
if (isBlock(node) || node.nodeName === 'BR') { | ||
@@ -532,3 +433,3 @@ if (prevText) { | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -556,3 +457,3 @@ | ||
*/ | ||
function remove(node) { | ||
function remove (node) { | ||
var next = node.nextSibling || node.parentNode; | ||
@@ -562,3 +463,3 @@ | ||
return next; | ||
return next | ||
} | ||
@@ -575,12 +476,10 @@ | ||
*/ | ||
function next(prev, current, isPre) { | ||
if (prev && prev.parentNode === current || isPre(current)) { | ||
return current.nextSibling || current.parentNode; | ||
function next (prev, current, isPre) { | ||
if ((prev && prev.parentNode === current) || isPre(current)) { | ||
return current.nextSibling || current.parentNode | ||
} | ||
return current.firstChild || current.nextSibling || current.parentNode; | ||
return current.firstChild || current.nextSibling || current.parentNode | ||
} | ||
var whitespace = collapseWhitespace; | ||
/* | ||
@@ -615,12 +514,7 @@ * Set up window for Node.js | ||
// For Node.js environments | ||
if (typeof document === 'undefined') { | ||
var JSDOM = require('jsdom').JSDOM; | ||
Parser.prototype.parseFromString = function (string) { | ||
return new JSDOM(string).window.document | ||
}; | ||
} else { | ||
if (!shouldUseActiveX()) { | ||
{ | ||
if (shouldUseActiveX()) { | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = document.implementation.createHTMLDocument(''); | ||
var doc = new window.ActiveXObject('htmlfile'); | ||
doc.designMode = 'on'; // disable on-page scripts | ||
doc.open(); | ||
@@ -633,4 +527,3 @@ doc.write(string); | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = new window.ActiveXObject('htmlfile'); | ||
doc.designMode = 'on'; // disable on-page scripts | ||
var doc = document.implementation.createHTMLDocument(''); | ||
doc.open(); | ||
@@ -672,3 +565,7 @@ doc.write(string); | ||
} | ||
whitespace(root, isBlock); | ||
collapseWhitespace({ | ||
element: root, | ||
isBlock: isBlock, | ||
isVoid: isVoid | ||
}); | ||
@@ -686,3 +583,2 @@ return root | ||
node.isBlock = isBlock(node); | ||
node.isVoid = isVoid$1(node); | ||
node.isCode = node.nodeName.toLowerCase() === 'code' || node.parentNode.isCode; | ||
@@ -694,14 +590,8 @@ node.isBlank = isBlank(node); | ||
function isVoid$1 (node) { | ||
return [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
function isBlank (node) { | ||
return ( | ||
!isVoid$1(node) && | ||
['A', 'TH', 'TD'].indexOf(node.nodeName) === -1 && | ||
/^\s*$/i.test(node.textContent) | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
) | ||
@@ -714,3 +604,3 @@ } | ||
if (!isBlock(node)) { | ||
if (!node.isBlock) { | ||
var hasLeading = /^[ \r\n\t]/.test(node.textContent); | ||
@@ -717,0 +607,0 @@ var hasTrailing = /[ \r\n\t]$/.test(node.textContent); |
@@ -17,13 +17,29 @@ 'use strict'; | ||
var blockElements = [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
]; | ||
function isBlock (node) { | ||
return [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
]; | ||
function isVoid (node) { | ||
return voidElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
} | ||
var rules = {}; | ||
@@ -223,2 +239,3 @@ | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.emDelimiter + content + options.emDelimiter | ||
@@ -232,2 +249,3 @@ } | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.strongDelimiter + content + options.strongDelimiter | ||
@@ -246,2 +264,4 @@ } | ||
replacement: function (content) { | ||
if (!content.trim()) return '' | ||
var delimiter = '`'; | ||
@@ -355,134 +375,16 @@ var leadingSpace = ''; | ||
/** | ||
* This file automatically generated from `pre-publish.js`. | ||
* Do not manually edit. | ||
*/ | ||
var voidElements = { | ||
"area": true, | ||
"base": true, | ||
"br": true, | ||
"col": true, | ||
"embed": true, | ||
"hr": true, | ||
"img": true, | ||
"input": true, | ||
"keygen": true, | ||
"link": true, | ||
"menuitem": true, | ||
"meta": true, | ||
"param": true, | ||
"source": true, | ||
"track": true, | ||
"wbr": true | ||
}; | ||
/** | ||
* This file automatically generated from `build.js`. | ||
* Do not manually edit. | ||
*/ | ||
var blockElements$1 = [ | ||
"address", | ||
"article", | ||
"aside", | ||
"blockquote", | ||
"canvas", | ||
"dd", | ||
"div", | ||
"dl", | ||
"dt", | ||
"fieldset", | ||
"figcaption", | ||
"figure", | ||
"footer", | ||
"form", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6", | ||
"header", | ||
"hgroup", | ||
"hr", | ||
"li", | ||
"main", | ||
"nav", | ||
"noscript", | ||
"ol", | ||
"output", | ||
"p", | ||
"pre", | ||
"section", | ||
"table", | ||
"tfoot", | ||
"ul", | ||
"video" | ||
]; | ||
'use strict'; | ||
Object.keys(voidElements).forEach(function (name) { | ||
voidElements[name.toUpperCase()] = 1; | ||
}); | ||
var blockElements = {}; | ||
blockElements$1.forEach(function (name) { | ||
blockElements[name.toUpperCase()] = 1; | ||
}); | ||
/** | ||
* isBlockElem(node) determines if the given node is a block element. | ||
* collapseWhitespace(options) removes extraneous whitespace from an the given element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
* @param {Object} options | ||
*/ | ||
function isBlockElem(node) { | ||
return !!(node && blockElements[node.nodeName]); | ||
} | ||
function collapseWhitespace (options) { | ||
var element = options.element; | ||
var isBlock = options.isBlock; | ||
var isVoid = options.isVoid; | ||
var isPre = options.isPre || function (node) { | ||
return node.nodeName === 'PRE' | ||
}; | ||
/** | ||
* isPreElem(node) determines if the given node is a PRE element. | ||
* | ||
* Whitespace for PRE elements are not collapsed. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isPreElem(node) { | ||
return node.nodeName === 'PRE'; | ||
} | ||
if (!element.firstChild || isPre(element)) return | ||
/** | ||
* isVoid(node) determines if the given node is a void element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isVoid(node) { | ||
return !!(node && voidElements[node.nodeName]); | ||
} | ||
/** | ||
* whitespace(elem [, isBlock]) removes extraneous whitespace from an | ||
* the given element. The function isBlock may optionally be passed in | ||
* to determine whether or not an element is a block element; if none | ||
* is provided, defaults to using the list of block elements provided | ||
* by the `block-elements` module. | ||
* | ||
* @param {Node} elem | ||
* @param {Function} blockTest | ||
*/ | ||
function collapseWhitespace(elem, isBlock, isPre) { | ||
if (!elem.firstChild || elem.nodeName === 'PRE') return; | ||
if (typeof isBlock !== 'function') { | ||
isBlock = isBlockElem; | ||
} | ||
if (typeof isPre !== 'function') { | ||
isPre = isPreElem; | ||
} | ||
var prevText = null; | ||
@@ -492,10 +394,10 @@ var prevVoid = false; | ||
var prev = null; | ||
var node = next(prev, elem, isPre); | ||
var node = next(prev, element, isPre); | ||
while (node !== elem) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { | ||
// Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
while (node !== element) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { // Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
var text = node.data.replace(/[ \r\n\t]+/g, ' '); | ||
if ((!prevText || / $/.test(prevText.data)) && !prevVoid && text[0] === ' ') { | ||
if ((!prevText || / $/.test(prevText.data)) && | ||
!prevVoid && text[0] === ' ') { | ||
text = text.substr(1); | ||
@@ -507,3 +409,3 @@ } | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -514,4 +416,3 @@ | ||
prevText = node; | ||
} else if (node.nodeType === 1) { | ||
// Node.ELEMENT_NODE | ||
} else if (node.nodeType === 1) { // Node.ELEMENT_NODE | ||
if (isBlock(node) || node.nodeName === 'BR') { | ||
@@ -531,3 +432,3 @@ if (prevText) { | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -555,3 +456,3 @@ | ||
*/ | ||
function remove(node) { | ||
function remove (node) { | ||
var next = node.nextSibling || node.parentNode; | ||
@@ -561,3 +462,3 @@ | ||
return next; | ||
return next | ||
} | ||
@@ -574,12 +475,10 @@ | ||
*/ | ||
function next(prev, current, isPre) { | ||
if (prev && prev.parentNode === current || isPre(current)) { | ||
return current.nextSibling || current.parentNode; | ||
function next (prev, current, isPre) { | ||
if ((prev && prev.parentNode === current) || isPre(current)) { | ||
return current.nextSibling || current.parentNode | ||
} | ||
return current.firstChild || current.nextSibling || current.parentNode; | ||
return current.firstChild || current.nextSibling || current.parentNode | ||
} | ||
var whitespace = collapseWhitespace; | ||
/* | ||
@@ -614,12 +513,7 @@ * Set up window for Node.js | ||
// For Node.js environments | ||
if (typeof document === 'undefined') { | ||
var JSDOM = require('jsdom').JSDOM; | ||
Parser.prototype.parseFromString = function (string) { | ||
return new JSDOM(string).window.document | ||
}; | ||
} else { | ||
if (!shouldUseActiveX()) { | ||
{ | ||
if (shouldUseActiveX()) { | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = document.implementation.createHTMLDocument(''); | ||
var doc = new window.ActiveXObject('htmlfile'); | ||
doc.designMode = 'on'; // disable on-page scripts | ||
doc.open(); | ||
@@ -632,4 +526,3 @@ doc.write(string); | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = new window.ActiveXObject('htmlfile'); | ||
doc.designMode = 'on'; // disable on-page scripts | ||
var doc = document.implementation.createHTMLDocument(''); | ||
doc.open(); | ||
@@ -671,3 +564,7 @@ doc.write(string); | ||
} | ||
whitespace(root, isBlock); | ||
collapseWhitespace({ | ||
element: root, | ||
isBlock: isBlock, | ||
isVoid: isVoid | ||
}); | ||
@@ -685,3 +582,2 @@ return root | ||
node.isBlock = isBlock(node); | ||
node.isVoid = isVoid$1(node); | ||
node.isCode = node.nodeName.toLowerCase() === 'code' || node.parentNode.isCode; | ||
@@ -693,14 +589,8 @@ node.isBlank = isBlank(node); | ||
function isVoid$1 (node) { | ||
return [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
function isBlank (node) { | ||
return ( | ||
!isVoid$1(node) && | ||
['A', 'TH', 'TD'].indexOf(node.nodeName) === -1 && | ||
/^\s*$/i.test(node.textContent) | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
) | ||
@@ -713,3 +603,3 @@ } | ||
if (!isBlock(node)) { | ||
if (!node.isBlock) { | ||
var hasLeading = /^[ \r\n\t]/.test(node.textContent); | ||
@@ -716,0 +606,0 @@ var hasTrailing = /[ \r\n\t]$/.test(node.textContent); |
@@ -15,13 +15,29 @@ function extend (destination) { | ||
var blockElements = [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
]; | ||
function isBlock (node) { | ||
return [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
]; | ||
function isVoid (node) { | ||
return voidElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
} | ||
var rules = {}; | ||
@@ -221,2 +237,3 @@ | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.emDelimiter + content + options.emDelimiter | ||
@@ -230,2 +247,3 @@ } | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.strongDelimiter + content + options.strongDelimiter | ||
@@ -244,2 +262,4 @@ } | ||
replacement: function (content) { | ||
if (!content.trim()) return '' | ||
var delimiter = '`'; | ||
@@ -353,134 +373,16 @@ var leadingSpace = ''; | ||
/** | ||
* This file automatically generated from `pre-publish.js`. | ||
* Do not manually edit. | ||
*/ | ||
var voidElements = { | ||
"area": true, | ||
"base": true, | ||
"br": true, | ||
"col": true, | ||
"embed": true, | ||
"hr": true, | ||
"img": true, | ||
"input": true, | ||
"keygen": true, | ||
"link": true, | ||
"menuitem": true, | ||
"meta": true, | ||
"param": true, | ||
"source": true, | ||
"track": true, | ||
"wbr": true | ||
}; | ||
/** | ||
* This file automatically generated from `build.js`. | ||
* Do not manually edit. | ||
*/ | ||
var blockElements$1 = [ | ||
"address", | ||
"article", | ||
"aside", | ||
"blockquote", | ||
"canvas", | ||
"dd", | ||
"div", | ||
"dl", | ||
"dt", | ||
"fieldset", | ||
"figcaption", | ||
"figure", | ||
"footer", | ||
"form", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6", | ||
"header", | ||
"hgroup", | ||
"hr", | ||
"li", | ||
"main", | ||
"nav", | ||
"noscript", | ||
"ol", | ||
"output", | ||
"p", | ||
"pre", | ||
"section", | ||
"table", | ||
"tfoot", | ||
"ul", | ||
"video" | ||
]; | ||
'use strict'; | ||
Object.keys(voidElements).forEach(function (name) { | ||
voidElements[name.toUpperCase()] = 1; | ||
}); | ||
var blockElements = {}; | ||
blockElements$1.forEach(function (name) { | ||
blockElements[name.toUpperCase()] = 1; | ||
}); | ||
/** | ||
* isBlockElem(node) determines if the given node is a block element. | ||
* collapseWhitespace(options) removes extraneous whitespace from an the given element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
* @param {Object} options | ||
*/ | ||
function isBlockElem(node) { | ||
return !!(node && blockElements[node.nodeName]); | ||
} | ||
function collapseWhitespace (options) { | ||
var element = options.element; | ||
var isBlock = options.isBlock; | ||
var isVoid = options.isVoid; | ||
var isPre = options.isPre || function (node) { | ||
return node.nodeName === 'PRE' | ||
}; | ||
/** | ||
* isPreElem(node) determines if the given node is a PRE element. | ||
* | ||
* Whitespace for PRE elements are not collapsed. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isPreElem(node) { | ||
return node.nodeName === 'PRE'; | ||
} | ||
if (!element.firstChild || isPre(element)) return | ||
/** | ||
* isVoid(node) determines if the given node is a void element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isVoid(node) { | ||
return !!(node && voidElements[node.nodeName]); | ||
} | ||
/** | ||
* whitespace(elem [, isBlock]) removes extraneous whitespace from an | ||
* the given element. The function isBlock may optionally be passed in | ||
* to determine whether or not an element is a block element; if none | ||
* is provided, defaults to using the list of block elements provided | ||
* by the `block-elements` module. | ||
* | ||
* @param {Node} elem | ||
* @param {Function} blockTest | ||
*/ | ||
function collapseWhitespace(elem, isBlock, isPre) { | ||
if (!elem.firstChild || elem.nodeName === 'PRE') return; | ||
if (typeof isBlock !== 'function') { | ||
isBlock = isBlockElem; | ||
} | ||
if (typeof isPre !== 'function') { | ||
isPre = isPreElem; | ||
} | ||
var prevText = null; | ||
@@ -490,10 +392,10 @@ var prevVoid = false; | ||
var prev = null; | ||
var node = next(prev, elem, isPre); | ||
var node = next(prev, element, isPre); | ||
while (node !== elem) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { | ||
// Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
while (node !== element) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { // Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
var text = node.data.replace(/[ \r\n\t]+/g, ' '); | ||
if ((!prevText || / $/.test(prevText.data)) && !prevVoid && text[0] === ' ') { | ||
if ((!prevText || / $/.test(prevText.data)) && | ||
!prevVoid && text[0] === ' ') { | ||
text = text.substr(1); | ||
@@ -505,3 +407,3 @@ } | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -512,4 +414,3 @@ | ||
prevText = node; | ||
} else if (node.nodeType === 1) { | ||
// Node.ELEMENT_NODE | ||
} else if (node.nodeType === 1) { // Node.ELEMENT_NODE | ||
if (isBlock(node) || node.nodeName === 'BR') { | ||
@@ -529,3 +430,3 @@ if (prevText) { | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -553,3 +454,3 @@ | ||
*/ | ||
function remove(node) { | ||
function remove (node) { | ||
var next = node.nextSibling || node.parentNode; | ||
@@ -559,3 +460,3 @@ | ||
return next; | ||
return next | ||
} | ||
@@ -572,12 +473,10 @@ | ||
*/ | ||
function next(prev, current, isPre) { | ||
if (prev && prev.parentNode === current || isPre(current)) { | ||
return current.nextSibling || current.parentNode; | ||
function next (prev, current, isPre) { | ||
if ((prev && prev.parentNode === current) || isPre(current)) { | ||
return current.nextSibling || current.parentNode | ||
} | ||
return current.firstChild || current.nextSibling || current.parentNode; | ||
return current.firstChild || current.nextSibling || current.parentNode | ||
} | ||
var whitespace = collapseWhitespace; | ||
/* | ||
@@ -612,12 +511,7 @@ * Set up window for Node.js | ||
// For Node.js environments | ||
if (typeof document === 'undefined') { | ||
var JSDOM = require('jsdom').JSDOM; | ||
Parser.prototype.parseFromString = function (string) { | ||
return new JSDOM(string).window.document | ||
}; | ||
} else { | ||
if (!shouldUseActiveX()) { | ||
{ | ||
if (shouldUseActiveX()) { | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = document.implementation.createHTMLDocument(''); | ||
var doc = new window.ActiveXObject('htmlfile'); | ||
doc.designMode = 'on'; // disable on-page scripts | ||
doc.open(); | ||
@@ -630,4 +524,3 @@ doc.write(string); | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = new window.ActiveXObject('htmlfile'); | ||
doc.designMode = 'on'; // disable on-page scripts | ||
var doc = document.implementation.createHTMLDocument(''); | ||
doc.open(); | ||
@@ -669,3 +562,7 @@ doc.write(string); | ||
} | ||
whitespace(root, isBlock); | ||
collapseWhitespace({ | ||
element: root, | ||
isBlock: isBlock, | ||
isVoid: isVoid | ||
}); | ||
@@ -683,3 +580,2 @@ return root | ||
node.isBlock = isBlock(node); | ||
node.isVoid = isVoid$1(node); | ||
node.isCode = node.nodeName.toLowerCase() === 'code' || node.parentNode.isCode; | ||
@@ -691,14 +587,8 @@ node.isBlank = isBlank(node); | ||
function isVoid$1 (node) { | ||
return [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
function isBlank (node) { | ||
return ( | ||
!isVoid$1(node) && | ||
['A', 'TH', 'TD'].indexOf(node.nodeName) === -1 && | ||
/^\s*$/i.test(node.textContent) | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
) | ||
@@ -711,3 +601,3 @@ } | ||
if (!isBlock(node)) { | ||
if (!node.isBlock) { | ||
var hasLeading = /^[ \r\n\t]/.test(node.textContent); | ||
@@ -714,0 +604,0 @@ var hasTrailing = /[ \r\n\t]$/.test(node.textContent); |
@@ -17,13 +17,29 @@ 'use strict'; | ||
var blockElements = [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
]; | ||
function isBlock (node) { | ||
return [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
]; | ||
function isVoid (node) { | ||
return voidElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
} | ||
var rules = {}; | ||
@@ -223,2 +239,3 @@ | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.emDelimiter + content + options.emDelimiter | ||
@@ -232,2 +249,3 @@ } | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.strongDelimiter + content + options.strongDelimiter | ||
@@ -246,2 +264,4 @@ } | ||
replacement: function (content) { | ||
if (!content.trim()) return '' | ||
var delimiter = '`'; | ||
@@ -355,134 +375,16 @@ var leadingSpace = ''; | ||
/** | ||
* This file automatically generated from `pre-publish.js`. | ||
* Do not manually edit. | ||
*/ | ||
var voidElements = { | ||
"area": true, | ||
"base": true, | ||
"br": true, | ||
"col": true, | ||
"embed": true, | ||
"hr": true, | ||
"img": true, | ||
"input": true, | ||
"keygen": true, | ||
"link": true, | ||
"menuitem": true, | ||
"meta": true, | ||
"param": true, | ||
"source": true, | ||
"track": true, | ||
"wbr": true | ||
}; | ||
/** | ||
* This file automatically generated from `build.js`. | ||
* Do not manually edit. | ||
*/ | ||
var blockElements$1 = [ | ||
"address", | ||
"article", | ||
"aside", | ||
"blockquote", | ||
"canvas", | ||
"dd", | ||
"div", | ||
"dl", | ||
"dt", | ||
"fieldset", | ||
"figcaption", | ||
"figure", | ||
"footer", | ||
"form", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6", | ||
"header", | ||
"hgroup", | ||
"hr", | ||
"li", | ||
"main", | ||
"nav", | ||
"noscript", | ||
"ol", | ||
"output", | ||
"p", | ||
"pre", | ||
"section", | ||
"table", | ||
"tfoot", | ||
"ul", | ||
"video" | ||
]; | ||
'use strict'; | ||
Object.keys(voidElements).forEach(function (name) { | ||
voidElements[name.toUpperCase()] = 1; | ||
}); | ||
var blockElements = {}; | ||
blockElements$1.forEach(function (name) { | ||
blockElements[name.toUpperCase()] = 1; | ||
}); | ||
/** | ||
* isBlockElem(node) determines if the given node is a block element. | ||
* collapseWhitespace(options) removes extraneous whitespace from an the given element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
* @param {Object} options | ||
*/ | ||
function isBlockElem(node) { | ||
return !!(node && blockElements[node.nodeName]); | ||
} | ||
function collapseWhitespace (options) { | ||
var element = options.element; | ||
var isBlock = options.isBlock; | ||
var isVoid = options.isVoid; | ||
var isPre = options.isPre || function (node) { | ||
return node.nodeName === 'PRE' | ||
}; | ||
/** | ||
* isPreElem(node) determines if the given node is a PRE element. | ||
* | ||
* Whitespace for PRE elements are not collapsed. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isPreElem(node) { | ||
return node.nodeName === 'PRE'; | ||
} | ||
if (!element.firstChild || isPre(element)) return | ||
/** | ||
* isVoid(node) determines if the given node is a void element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isVoid(node) { | ||
return !!(node && voidElements[node.nodeName]); | ||
} | ||
/** | ||
* whitespace(elem [, isBlock]) removes extraneous whitespace from an | ||
* the given element. The function isBlock may optionally be passed in | ||
* to determine whether or not an element is a block element; if none | ||
* is provided, defaults to using the list of block elements provided | ||
* by the `block-elements` module. | ||
* | ||
* @param {Node} elem | ||
* @param {Function} blockTest | ||
*/ | ||
function collapseWhitespace(elem, isBlock, isPre) { | ||
if (!elem.firstChild || elem.nodeName === 'PRE') return; | ||
if (typeof isBlock !== 'function') { | ||
isBlock = isBlockElem; | ||
} | ||
if (typeof isPre !== 'function') { | ||
isPre = isPreElem; | ||
} | ||
var prevText = null; | ||
@@ -492,10 +394,10 @@ var prevVoid = false; | ||
var prev = null; | ||
var node = next(prev, elem, isPre); | ||
var node = next(prev, element, isPre); | ||
while (node !== elem) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { | ||
// Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
while (node !== element) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { // Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
var text = node.data.replace(/[ \r\n\t]+/g, ' '); | ||
if ((!prevText || / $/.test(prevText.data)) && !prevVoid && text[0] === ' ') { | ||
if ((!prevText || / $/.test(prevText.data)) && | ||
!prevVoid && text[0] === ' ') { | ||
text = text.substr(1); | ||
@@ -507,3 +409,3 @@ } | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -514,4 +416,3 @@ | ||
prevText = node; | ||
} else if (node.nodeType === 1) { | ||
// Node.ELEMENT_NODE | ||
} else if (node.nodeType === 1) { // Node.ELEMENT_NODE | ||
if (isBlock(node) || node.nodeName === 'BR') { | ||
@@ -531,3 +432,3 @@ if (prevText) { | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -555,3 +456,3 @@ | ||
*/ | ||
function remove(node) { | ||
function remove (node) { | ||
var next = node.nextSibling || node.parentNode; | ||
@@ -561,3 +462,3 @@ | ||
return next; | ||
return next | ||
} | ||
@@ -574,12 +475,10 @@ | ||
*/ | ||
function next(prev, current, isPre) { | ||
if (prev && prev.parentNode === current || isPre(current)) { | ||
return current.nextSibling || current.parentNode; | ||
function next (prev, current, isPre) { | ||
if ((prev && prev.parentNode === current) || isPre(current)) { | ||
return current.nextSibling || current.parentNode | ||
} | ||
return current.firstChild || current.nextSibling || current.parentNode; | ||
return current.firstChild || current.nextSibling || current.parentNode | ||
} | ||
var whitespace = collapseWhitespace; | ||
/* | ||
@@ -614,4 +513,3 @@ * Set up window for Node.js | ||
// For Node.js environments | ||
if (typeof document === 'undefined') { | ||
{ | ||
var JSDOM = require('jsdom').JSDOM; | ||
@@ -621,21 +519,2 @@ Parser.prototype.parseFromString = function (string) { | ||
}; | ||
} else { | ||
if (!shouldUseActiveX()) { | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = document.implementation.createHTMLDocument(''); | ||
doc.open(); | ||
doc.write(string); | ||
doc.close(); | ||
return doc | ||
}; | ||
} else { | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = new window.ActiveXObject('htmlfile'); | ||
doc.designMode = 'on'; // disable on-page scripts | ||
doc.open(); | ||
doc.write(string); | ||
doc.close(); | ||
return doc | ||
}; | ||
} | ||
} | ||
@@ -645,12 +524,2 @@ return Parser | ||
function shouldUseActiveX () { | ||
var useActiveX = false; | ||
try { | ||
document.implementation.createHTMLDocument('').open(); | ||
} catch (e) { | ||
if (window.ActiveXObject) useActiveX = true; | ||
} | ||
return useActiveX | ||
} | ||
var HTMLParser = canParseHTMLNatively() ? root.DOMParser : createHTMLParser(); | ||
@@ -672,3 +541,7 @@ | ||
} | ||
whitespace(root, isBlock); | ||
collapseWhitespace({ | ||
element: root, | ||
isBlock: isBlock, | ||
isVoid: isVoid | ||
}); | ||
@@ -686,3 +559,2 @@ return root | ||
node.isBlock = isBlock(node); | ||
node.isVoid = isVoid$1(node); | ||
node.isCode = node.nodeName.toLowerCase() === 'code' || node.parentNode.isCode; | ||
@@ -694,14 +566,8 @@ node.isBlank = isBlank(node); | ||
function isVoid$1 (node) { | ||
return [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
function isBlank (node) { | ||
return ( | ||
!isVoid$1(node) && | ||
['A', 'TH', 'TD'].indexOf(node.nodeName) === -1 && | ||
/^\s*$/i.test(node.textContent) | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
) | ||
@@ -714,3 +580,3 @@ } | ||
if (!isBlock(node)) { | ||
if (!node.isBlock) { | ||
var hasLeading = /^[ \r\n\t]/.test(node.textContent); | ||
@@ -717,0 +583,0 @@ var hasTrailing = /[ \r\n\t]$/.test(node.textContent); |
@@ -15,13 +15,29 @@ function extend (destination) { | ||
var blockElements = [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
]; | ||
function isBlock (node) { | ||
return [ | ||
'address', 'article', 'aside', 'audio', 'blockquote', 'body', 'canvas', | ||
'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption', | ||
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav', | ||
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table', | ||
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
]; | ||
function isVoid (node) { | ||
return voidElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
} | ||
var rules = {}; | ||
@@ -221,2 +237,3 @@ | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.emDelimiter + content + options.emDelimiter | ||
@@ -230,2 +247,3 @@ } | ||
replacement: function (content, node, options) { | ||
if (!content.trim()) return '' | ||
return options.strongDelimiter + content + options.strongDelimiter | ||
@@ -244,2 +262,4 @@ } | ||
replacement: function (content) { | ||
if (!content.trim()) return '' | ||
var delimiter = '`'; | ||
@@ -353,134 +373,16 @@ var leadingSpace = ''; | ||
/** | ||
* This file automatically generated from `pre-publish.js`. | ||
* Do not manually edit. | ||
*/ | ||
var voidElements = { | ||
"area": true, | ||
"base": true, | ||
"br": true, | ||
"col": true, | ||
"embed": true, | ||
"hr": true, | ||
"img": true, | ||
"input": true, | ||
"keygen": true, | ||
"link": true, | ||
"menuitem": true, | ||
"meta": true, | ||
"param": true, | ||
"source": true, | ||
"track": true, | ||
"wbr": true | ||
}; | ||
/** | ||
* This file automatically generated from `build.js`. | ||
* Do not manually edit. | ||
*/ | ||
var blockElements$1 = [ | ||
"address", | ||
"article", | ||
"aside", | ||
"blockquote", | ||
"canvas", | ||
"dd", | ||
"div", | ||
"dl", | ||
"dt", | ||
"fieldset", | ||
"figcaption", | ||
"figure", | ||
"footer", | ||
"form", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6", | ||
"header", | ||
"hgroup", | ||
"hr", | ||
"li", | ||
"main", | ||
"nav", | ||
"noscript", | ||
"ol", | ||
"output", | ||
"p", | ||
"pre", | ||
"section", | ||
"table", | ||
"tfoot", | ||
"ul", | ||
"video" | ||
]; | ||
'use strict'; | ||
Object.keys(voidElements).forEach(function (name) { | ||
voidElements[name.toUpperCase()] = 1; | ||
}); | ||
var blockElements = {}; | ||
blockElements$1.forEach(function (name) { | ||
blockElements[name.toUpperCase()] = 1; | ||
}); | ||
/** | ||
* isBlockElem(node) determines if the given node is a block element. | ||
* collapseWhitespace(options) removes extraneous whitespace from an the given element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
* @param {Object} options | ||
*/ | ||
function isBlockElem(node) { | ||
return !!(node && blockElements[node.nodeName]); | ||
} | ||
function collapseWhitespace (options) { | ||
var element = options.element; | ||
var isBlock = options.isBlock; | ||
var isVoid = options.isVoid; | ||
var isPre = options.isPre || function (node) { | ||
return node.nodeName === 'PRE' | ||
}; | ||
/** | ||
* isPreElem(node) determines if the given node is a PRE element. | ||
* | ||
* Whitespace for PRE elements are not collapsed. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isPreElem(node) { | ||
return node.nodeName === 'PRE'; | ||
} | ||
if (!element.firstChild || isPre(element)) return | ||
/** | ||
* isVoid(node) determines if the given node is a void element. | ||
* | ||
* @param {Node} node | ||
* @return {Boolean} | ||
*/ | ||
function isVoid(node) { | ||
return !!(node && voidElements[node.nodeName]); | ||
} | ||
/** | ||
* whitespace(elem [, isBlock]) removes extraneous whitespace from an | ||
* the given element. The function isBlock may optionally be passed in | ||
* to determine whether or not an element is a block element; if none | ||
* is provided, defaults to using the list of block elements provided | ||
* by the `block-elements` module. | ||
* | ||
* @param {Node} elem | ||
* @param {Function} blockTest | ||
*/ | ||
function collapseWhitespace(elem, isBlock, isPre) { | ||
if (!elem.firstChild || elem.nodeName === 'PRE') return; | ||
if (typeof isBlock !== 'function') { | ||
isBlock = isBlockElem; | ||
} | ||
if (typeof isPre !== 'function') { | ||
isPre = isPreElem; | ||
} | ||
var prevText = null; | ||
@@ -490,10 +392,10 @@ var prevVoid = false; | ||
var prev = null; | ||
var node = next(prev, elem, isPre); | ||
var node = next(prev, element, isPre); | ||
while (node !== elem) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { | ||
// Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
while (node !== element) { | ||
if (node.nodeType === 3 || node.nodeType === 4) { // Node.TEXT_NODE or Node.CDATA_SECTION_NODE | ||
var text = node.data.replace(/[ \r\n\t]+/g, ' '); | ||
if ((!prevText || / $/.test(prevText.data)) && !prevVoid && text[0] === ' ') { | ||
if ((!prevText || / $/.test(prevText.data)) && | ||
!prevVoid && text[0] === ' ') { | ||
text = text.substr(1); | ||
@@ -505,3 +407,3 @@ } | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -512,4 +414,3 @@ | ||
prevText = node; | ||
} else if (node.nodeType === 1) { | ||
// Node.ELEMENT_NODE | ||
} else if (node.nodeType === 1) { // Node.ELEMENT_NODE | ||
if (isBlock(node) || node.nodeName === 'BR') { | ||
@@ -529,3 +430,3 @@ if (prevText) { | ||
node = remove(node); | ||
continue; | ||
continue | ||
} | ||
@@ -553,3 +454,3 @@ | ||
*/ | ||
function remove(node) { | ||
function remove (node) { | ||
var next = node.nextSibling || node.parentNode; | ||
@@ -559,3 +460,3 @@ | ||
return next; | ||
return next | ||
} | ||
@@ -572,12 +473,10 @@ | ||
*/ | ||
function next(prev, current, isPre) { | ||
if (prev && prev.parentNode === current || isPre(current)) { | ||
return current.nextSibling || current.parentNode; | ||
function next (prev, current, isPre) { | ||
if ((prev && prev.parentNode === current) || isPre(current)) { | ||
return current.nextSibling || current.parentNode | ||
} | ||
return current.firstChild || current.nextSibling || current.parentNode; | ||
return current.firstChild || current.nextSibling || current.parentNode | ||
} | ||
var whitespace = collapseWhitespace; | ||
/* | ||
@@ -612,4 +511,3 @@ * Set up window for Node.js | ||
// For Node.js environments | ||
if (typeof document === 'undefined') { | ||
{ | ||
var JSDOM = require('jsdom').JSDOM; | ||
@@ -619,21 +517,2 @@ Parser.prototype.parseFromString = function (string) { | ||
}; | ||
} else { | ||
if (!shouldUseActiveX()) { | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = document.implementation.createHTMLDocument(''); | ||
doc.open(); | ||
doc.write(string); | ||
doc.close(); | ||
return doc | ||
}; | ||
} else { | ||
Parser.prototype.parseFromString = function (string) { | ||
var doc = new window.ActiveXObject('htmlfile'); | ||
doc.designMode = 'on'; // disable on-page scripts | ||
doc.open(); | ||
doc.write(string); | ||
doc.close(); | ||
return doc | ||
}; | ||
} | ||
} | ||
@@ -643,12 +522,2 @@ return Parser | ||
function shouldUseActiveX () { | ||
var useActiveX = false; | ||
try { | ||
document.implementation.createHTMLDocument('').open(); | ||
} catch (e) { | ||
if (window.ActiveXObject) useActiveX = true; | ||
} | ||
return useActiveX | ||
} | ||
var HTMLParser = canParseHTMLNatively() ? root.DOMParser : createHTMLParser(); | ||
@@ -670,3 +539,7 @@ | ||
} | ||
whitespace(root, isBlock); | ||
collapseWhitespace({ | ||
element: root, | ||
isBlock: isBlock, | ||
isVoid: isVoid | ||
}); | ||
@@ -684,3 +557,2 @@ return root | ||
node.isBlock = isBlock(node); | ||
node.isVoid = isVoid$1(node); | ||
node.isCode = node.nodeName.toLowerCase() === 'code' || node.parentNode.isCode; | ||
@@ -692,14 +564,8 @@ node.isBlank = isBlank(node); | ||
function isVoid$1 (node) { | ||
return [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
].indexOf(node.nodeName.toLowerCase()) !== -1 | ||
} | ||
function isBlank (node) { | ||
return ( | ||
!isVoid$1(node) && | ||
['A', 'TH', 'TD'].indexOf(node.nodeName) === -1 && | ||
/^\s*$/i.test(node.textContent) | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
) | ||
@@ -712,3 +578,3 @@ } | ||
if (!isBlock(node)) { | ||
if (!node.isBlock) { | ||
var hasLeading = /^[ \r\n\t]/.test(node.textContent); | ||
@@ -715,0 +581,0 @@ var hasTrailing = /[ \r\n\t]$/.test(node.textContent); |
{ | ||
"name": "turndown", | ||
"description": "A library that converts HTML to Markdown", | ||
"version": "4.0.0-rc.3", | ||
"version": "4.0.0", | ||
"author": "Dom Christie", | ||
"main": "lib/turndown.cjs.js", | ||
"module": "lib/turndown.es.js", | ||
"jsnext:main": "lib/turndown.es.js", | ||
"browser": { | ||
@@ -10,3 +13,3 @@ "jsdom": false | ||
"dependencies": { | ||
"collapse-whitespace": "^1.1.2", | ||
"collapse-whitespace": "domchristie/collapse-whitespace#turndown", | ||
"jsdom": "^11.3.0" | ||
@@ -28,3 +31,2 @@ }, | ||
], | ||
"jsnext:main": "lib/turndown.es.js", | ||
"keywords": [ | ||
@@ -36,8 +38,11 @@ "converter", | ||
"license": "MIT", | ||
"main": "lib/turndown.cjs.js", | ||
"module": "lib/turndown.es.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/domchristie/turndown.git" | ||
}, | ||
"scripts": { | ||
"build": "npm run build-cjs && npm run build-es && npm run build-iife", | ||
"build": "npm run build-cjs && npm run build-es && npm run build-umd && npm run build-iife", | ||
"build-cjs": "rollup -c config/rollup.config.cjs.js && rollup -c config/rollup.config.browser.cjs.js", | ||
"build-es": "rollup -c config/rollup.config.es.js && rollup -c config/rollup.config.browser.es.js", | ||
"build-umd": "rollup -c config/rollup.config.umd.js && rollup -c config/rollup.config.browser.umd.js", | ||
"build-iife": "rollup -c config/rollup.config.iife.js", | ||
@@ -44,0 +49,0 @@ "build-test": "browserify test/turndown-test.js --outfile test/turndown-test.browser.js", |
# Turndown | ||
![](https://api.travis-ci.org/domchristie/turndown.svg) | ||
[![Build Status](https://travis-ci.org/domchristie/turndown.svg?branch=master)](https://travis-ci.org/domchristie/turndown) | ||
@@ -23,2 +23,4 @@ Convert HTML into Markdown with JavaScript. | ||
For usage with RequireJS, UMD versions are located in `lib/turndown.umd.js` (for Node.js) and `lib/turndown.browser.umd.js` for browser usage. These files are generated when the npm package is published. To generate them manually, clone this repo and run `npm run build`. | ||
## Usage | ||
@@ -25,0 +27,0 @@ |
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
167587
10
5247
1
208
0
1
1
- Removedblock-elements@1.2.0(transitive)
- Removedcollapse-whitespace@1.1.7(transitive)
- Removedvoid-elements@2.0.1(transitive)
Updatedcollapse-whitespace@domchristie/collapse-whitespace#turndown