turndown
Advanced tools
Comparing version 6.0.0 to 7.0.0
@@ -19,28 +19,53 @@ 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' | ||
'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 blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return is(node, blockElements) | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
'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 | ||
return is(node, voidElements) | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
return has(node, voidElements) | ||
} | ||
var meaningfulWhenBlankElements = [ | ||
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT', | ||
'AUDIO', 'VIDEO' | ||
]; | ||
function isMeaningfulWhenBlank (node) { | ||
return is(node, meaningfulWhenBlankElements) | ||
} | ||
function hasMeaningfulWhenBlank (node) { | ||
return has(node, meaningfulWhenBlankElements) | ||
} | ||
function is (node, tagNames) { | ||
return tagNames.indexOf(node.nodeName) >= 0 | ||
} | ||
function has (node, tagNames) { | ||
return ( | ||
node.getElementsByTagName && | ||
tagNames.some(function (tagName) { | ||
return node.getElementsByTagName(tagName).length | ||
}) | ||
) | ||
} | ||
var rules = {}; | ||
@@ -155,3 +180,3 @@ | ||
replacement: function (content, node, options) { | ||
var className = node.firstChild.className || ''; | ||
var className = node.firstChild.getAttribute('class') || ''; | ||
var language = (className.match(/language-(\S+)/) || [null, ''])[1]; | ||
@@ -200,3 +225,4 @@ var code = node.firstChild.textContent; | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
return '[' + content + '](' + href + title + ')' | ||
@@ -217,3 +243,4 @@ } | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
var replacement; | ||
@@ -300,5 +327,5 @@ var reference; | ||
replacement: function (content, node) { | ||
var alt = node.alt || ''; | ||
var alt = cleanAttribute(node.getAttribute('alt')); | ||
var src = node.getAttribute('src') || ''; | ||
var title = node.title || ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
var titlePart = title ? ' "' + title + '"' : ''; | ||
@@ -309,2 +336,6 @@ return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : '' | ||
function cleanAttribute (attribute) { | ||
return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : '' | ||
} | ||
/** | ||
@@ -623,6 +654,7 @@ * Manages a collection of rules used to convert HTML to Markdown | ||
return ( | ||
['A', 'TH', 'TD', 'IFRAME', 'SCRIPT', 'AUDIO', 'VIDEO'].indexOf(node.nodeName) === -1 && | ||
!isVoid(node) && | ||
!isMeaningfulWhenBlank(node) && | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
!hasVoid(node) && | ||
!hasMeaningfulWhenBlank(node) | ||
) | ||
@@ -629,0 +661,0 @@ } |
@@ -18,28 +18,53 @@ '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' | ||
'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 blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return is(node, blockElements) | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
'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 | ||
return is(node, voidElements) | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
return has(node, voidElements) | ||
} | ||
var meaningfulWhenBlankElements = [ | ||
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT', | ||
'AUDIO', 'VIDEO' | ||
]; | ||
function isMeaningfulWhenBlank (node) { | ||
return is(node, meaningfulWhenBlankElements) | ||
} | ||
function hasMeaningfulWhenBlank (node) { | ||
return has(node, meaningfulWhenBlankElements) | ||
} | ||
function is (node, tagNames) { | ||
return tagNames.indexOf(node.nodeName) >= 0 | ||
} | ||
function has (node, tagNames) { | ||
return ( | ||
node.getElementsByTagName && | ||
tagNames.some(function (tagName) { | ||
return node.getElementsByTagName(tagName).length | ||
}) | ||
) | ||
} | ||
var rules = {}; | ||
@@ -154,3 +179,3 @@ | ||
replacement: function (content, node, options) { | ||
var className = node.firstChild.className || ''; | ||
var className = node.firstChild.getAttribute('class') || ''; | ||
var language = (className.match(/language-(\S+)/) || [null, ''])[1]; | ||
@@ -199,3 +224,4 @@ var code = node.firstChild.textContent; | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
return '[' + content + '](' + href + title + ')' | ||
@@ -216,3 +242,4 @@ } | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
var replacement; | ||
@@ -299,5 +326,5 @@ var reference; | ||
replacement: function (content, node) { | ||
var alt = node.alt || ''; | ||
var alt = cleanAttribute(node.getAttribute('alt')); | ||
var src = node.getAttribute('src') || ''; | ||
var title = node.title || ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
var titlePart = title ? ' "' + title + '"' : ''; | ||
@@ -308,2 +335,6 @@ return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : '' | ||
function cleanAttribute (attribute) { | ||
return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : '' | ||
} | ||
/** | ||
@@ -622,6 +653,7 @@ * Manages a collection of rules used to convert HTML to Markdown | ||
return ( | ||
['A', 'TH', 'TD', 'IFRAME', 'SCRIPT', 'AUDIO', 'VIDEO'].indexOf(node.nodeName) === -1 && | ||
!isVoid(node) && | ||
!isMeaningfulWhenBlank(node) && | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
!hasVoid(node) && | ||
!hasMeaningfulWhenBlank(node) | ||
) | ||
@@ -628,0 +660,0 @@ } |
@@ -16,28 +16,53 @@ 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' | ||
'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 blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return is(node, blockElements) | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
'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 | ||
return is(node, voidElements) | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
return has(node, voidElements) | ||
} | ||
var meaningfulWhenBlankElements = [ | ||
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT', | ||
'AUDIO', 'VIDEO' | ||
]; | ||
function isMeaningfulWhenBlank (node) { | ||
return is(node, meaningfulWhenBlankElements) | ||
} | ||
function hasMeaningfulWhenBlank (node) { | ||
return has(node, meaningfulWhenBlankElements) | ||
} | ||
function is (node, tagNames) { | ||
return tagNames.indexOf(node.nodeName) >= 0 | ||
} | ||
function has (node, tagNames) { | ||
return ( | ||
node.getElementsByTagName && | ||
tagNames.some(function (tagName) { | ||
return node.getElementsByTagName(tagName).length | ||
}) | ||
) | ||
} | ||
var rules = {}; | ||
@@ -152,3 +177,3 @@ | ||
replacement: function (content, node, options) { | ||
var className = node.firstChild.className || ''; | ||
var className = node.firstChild.getAttribute('class') || ''; | ||
var language = (className.match(/language-(\S+)/) || [null, ''])[1]; | ||
@@ -197,3 +222,4 @@ var code = node.firstChild.textContent; | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
return '[' + content + '](' + href + title + ')' | ||
@@ -214,3 +240,4 @@ } | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
var replacement; | ||
@@ -297,5 +324,5 @@ var reference; | ||
replacement: function (content, node) { | ||
var alt = node.alt || ''; | ||
var alt = cleanAttribute(node.getAttribute('alt')); | ||
var src = node.getAttribute('src') || ''; | ||
var title = node.title || ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
var titlePart = title ? ' "' + title + '"' : ''; | ||
@@ -306,2 +333,6 @@ return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : '' | ||
function cleanAttribute (attribute) { | ||
return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : '' | ||
} | ||
/** | ||
@@ -620,6 +651,7 @@ * Manages a collection of rules used to convert HTML to Markdown | ||
return ( | ||
['A', 'TH', 'TD', 'IFRAME', 'SCRIPT', 'AUDIO', 'VIDEO'].indexOf(node.nodeName) === -1 && | ||
!isVoid(node) && | ||
!isMeaningfulWhenBlank(node) && | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
!hasVoid(node) && | ||
!hasMeaningfulWhenBlank(node) | ||
) | ||
@@ -626,0 +658,0 @@ } |
@@ -22,28 +22,53 @@ (function (global, factory) { | ||
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' | ||
'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 blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return is(node, blockElements) | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
'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 | ||
return is(node, voidElements) | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
return has(node, voidElements) | ||
} | ||
var meaningfulWhenBlankElements = [ | ||
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT', | ||
'AUDIO', 'VIDEO' | ||
]; | ||
function isMeaningfulWhenBlank (node) { | ||
return is(node, meaningfulWhenBlankElements) | ||
} | ||
function hasMeaningfulWhenBlank (node) { | ||
return has(node, meaningfulWhenBlankElements) | ||
} | ||
function is (node, tagNames) { | ||
return tagNames.indexOf(node.nodeName) >= 0 | ||
} | ||
function has (node, tagNames) { | ||
return ( | ||
node.getElementsByTagName && | ||
tagNames.some(function (tagName) { | ||
return node.getElementsByTagName(tagName).length | ||
}) | ||
) | ||
} | ||
var rules = {}; | ||
@@ -158,3 +183,3 @@ | ||
replacement: function (content, node, options) { | ||
var className = node.firstChild.className || ''; | ||
var className = node.firstChild.getAttribute('class') || ''; | ||
var language = (className.match(/language-(\S+)/) || [null, ''])[1]; | ||
@@ -203,3 +228,4 @@ var code = node.firstChild.textContent; | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
return '[' + content + '](' + href + title + ')' | ||
@@ -220,3 +246,4 @@ } | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
var replacement; | ||
@@ -303,5 +330,5 @@ var reference; | ||
replacement: function (content, node) { | ||
var alt = node.alt || ''; | ||
var alt = cleanAttribute(node.getAttribute('alt')); | ||
var src = node.getAttribute('src') || ''; | ||
var title = node.title || ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
var titlePart = title ? ' "' + title + '"' : ''; | ||
@@ -312,2 +339,6 @@ return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : '' | ||
function cleanAttribute (attribute) { | ||
return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : '' | ||
} | ||
/** | ||
@@ -626,6 +657,7 @@ * Manages a collection of rules used to convert HTML to Markdown | ||
return ( | ||
['A', 'TH', 'TD', 'IFRAME', 'SCRIPT', 'AUDIO', 'VIDEO'].indexOf(node.nodeName) === -1 && | ||
!isVoid(node) && | ||
!isMeaningfulWhenBlank(node) && | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
!hasVoid(node) && | ||
!hasMeaningfulWhenBlank(node) | ||
) | ||
@@ -632,0 +664,0 @@ } |
@@ -18,28 +18,53 @@ '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' | ||
'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 blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return is(node, blockElements) | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
'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 | ||
return is(node, voidElements) | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
return has(node, voidElements) | ||
} | ||
var meaningfulWhenBlankElements = [ | ||
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT', | ||
'AUDIO', 'VIDEO' | ||
]; | ||
function isMeaningfulWhenBlank (node) { | ||
return is(node, meaningfulWhenBlankElements) | ||
} | ||
function hasMeaningfulWhenBlank (node) { | ||
return has(node, meaningfulWhenBlankElements) | ||
} | ||
function is (node, tagNames) { | ||
return tagNames.indexOf(node.nodeName) >= 0 | ||
} | ||
function has (node, tagNames) { | ||
return ( | ||
node.getElementsByTagName && | ||
tagNames.some(function (tagName) { | ||
return node.getElementsByTagName(tagName).length | ||
}) | ||
) | ||
} | ||
var rules = {}; | ||
@@ -154,3 +179,3 @@ | ||
replacement: function (content, node, options) { | ||
var className = node.firstChild.className || ''; | ||
var className = node.firstChild.getAttribute('class') || ''; | ||
var language = (className.match(/language-(\S+)/) || [null, ''])[1]; | ||
@@ -199,3 +224,4 @@ var code = node.firstChild.textContent; | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
return '[' + content + '](' + href + title + ')' | ||
@@ -216,3 +242,4 @@ } | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
var replacement; | ||
@@ -299,5 +326,5 @@ var reference; | ||
replacement: function (content, node) { | ||
var alt = node.alt || ''; | ||
var alt = cleanAttribute(node.getAttribute('alt')); | ||
var src = node.getAttribute('src') || ''; | ||
var title = node.title || ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
var titlePart = title ? ' "' + title + '"' : ''; | ||
@@ -308,2 +335,6 @@ return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : '' | ||
function cleanAttribute (attribute) { | ||
return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : '' | ||
} | ||
/** | ||
@@ -549,5 +580,5 @@ * Manages a collection of rules used to convert HTML to Markdown | ||
{ | ||
var JSDOM = require('jsdom').JSDOM; | ||
var domino = require('domino'); | ||
Parser.prototype.parseFromString = function (string) { | ||
return new JSDOM(string).window.document | ||
return domino.createDocument(string) | ||
}; | ||
@@ -599,6 +630,7 @@ } | ||
return ( | ||
['A', 'TH', 'TD', 'IFRAME', 'SCRIPT', 'AUDIO', 'VIDEO'].indexOf(node.nodeName) === -1 && | ||
!isVoid(node) && | ||
!isMeaningfulWhenBlank(node) && | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
!hasVoid(node) && | ||
!hasMeaningfulWhenBlank(node) | ||
) | ||
@@ -605,0 +637,0 @@ } |
@@ -16,28 +16,53 @@ 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' | ||
'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 blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return is(node, blockElements) | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
'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 | ||
return is(node, voidElements) | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
return has(node, voidElements) | ||
} | ||
var meaningfulWhenBlankElements = [ | ||
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT', | ||
'AUDIO', 'VIDEO' | ||
]; | ||
function isMeaningfulWhenBlank (node) { | ||
return is(node, meaningfulWhenBlankElements) | ||
} | ||
function hasMeaningfulWhenBlank (node) { | ||
return has(node, meaningfulWhenBlankElements) | ||
} | ||
function is (node, tagNames) { | ||
return tagNames.indexOf(node.nodeName) >= 0 | ||
} | ||
function has (node, tagNames) { | ||
return ( | ||
node.getElementsByTagName && | ||
tagNames.some(function (tagName) { | ||
return node.getElementsByTagName(tagName).length | ||
}) | ||
) | ||
} | ||
var rules = {}; | ||
@@ -152,3 +177,3 @@ | ||
replacement: function (content, node, options) { | ||
var className = node.firstChild.className || ''; | ||
var className = node.firstChild.getAttribute('class') || ''; | ||
var language = (className.match(/language-(\S+)/) || [null, ''])[1]; | ||
@@ -197,3 +222,4 @@ var code = node.firstChild.textContent; | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
return '[' + content + '](' + href + title + ')' | ||
@@ -214,3 +240,4 @@ } | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
var replacement; | ||
@@ -297,5 +324,5 @@ var reference; | ||
replacement: function (content, node) { | ||
var alt = node.alt || ''; | ||
var alt = cleanAttribute(node.getAttribute('alt')); | ||
var src = node.getAttribute('src') || ''; | ||
var title = node.title || ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
var titlePart = title ? ' "' + title + '"' : ''; | ||
@@ -306,2 +333,6 @@ return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : '' | ||
function cleanAttribute (attribute) { | ||
return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : '' | ||
} | ||
/** | ||
@@ -547,5 +578,5 @@ * Manages a collection of rules used to convert HTML to Markdown | ||
{ | ||
var JSDOM = require('jsdom').JSDOM; | ||
var domino = require('domino'); | ||
Parser.prototype.parseFromString = function (string) { | ||
return new JSDOM(string).window.document | ||
return domino.createDocument(string) | ||
}; | ||
@@ -597,6 +628,7 @@ } | ||
return ( | ||
['A', 'TH', 'TD', 'IFRAME', 'SCRIPT', 'AUDIO', 'VIDEO'].indexOf(node.nodeName) === -1 && | ||
!isVoid(node) && | ||
!isMeaningfulWhenBlank(node) && | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
!hasVoid(node) && | ||
!hasMeaningfulWhenBlank(node) | ||
) | ||
@@ -603,0 +635,0 @@ } |
@@ -22,28 +22,53 @@ (function (global, factory) { | ||
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' | ||
'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 blockElements.indexOf(node.nodeName.toLowerCase()) !== -1 | ||
return is(node, blockElements) | ||
} | ||
var voidElements = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', | ||
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' | ||
'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 | ||
return is(node, voidElements) | ||
} | ||
var voidSelector = voidElements.join(); | ||
function hasVoid (node) { | ||
return node.querySelector && node.querySelector(voidSelector) | ||
return has(node, voidElements) | ||
} | ||
var meaningfulWhenBlankElements = [ | ||
'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT', | ||
'AUDIO', 'VIDEO' | ||
]; | ||
function isMeaningfulWhenBlank (node) { | ||
return is(node, meaningfulWhenBlankElements) | ||
} | ||
function hasMeaningfulWhenBlank (node) { | ||
return has(node, meaningfulWhenBlankElements) | ||
} | ||
function is (node, tagNames) { | ||
return tagNames.indexOf(node.nodeName) >= 0 | ||
} | ||
function has (node, tagNames) { | ||
return ( | ||
node.getElementsByTagName && | ||
tagNames.some(function (tagName) { | ||
return node.getElementsByTagName(tagName).length | ||
}) | ||
) | ||
} | ||
var rules = {}; | ||
@@ -158,3 +183,3 @@ | ||
replacement: function (content, node, options) { | ||
var className = node.firstChild.className || ''; | ||
var className = node.firstChild.getAttribute('class') || ''; | ||
var language = (className.match(/language-(\S+)/) || [null, ''])[1]; | ||
@@ -203,3 +228,4 @@ var code = node.firstChild.textContent; | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
return '[' + content + '](' + href + title + ')' | ||
@@ -220,3 +246,4 @@ } | ||
var href = node.getAttribute('href'); | ||
var title = node.title ? ' "' + node.title + '"' : ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
if (title) title = ' "' + title + '"'; | ||
var replacement; | ||
@@ -303,5 +330,5 @@ var reference; | ||
replacement: function (content, node) { | ||
var alt = node.alt || ''; | ||
var alt = cleanAttribute(node.getAttribute('alt')); | ||
var src = node.getAttribute('src') || ''; | ||
var title = node.title || ''; | ||
var title = cleanAttribute(node.getAttribute('title')); | ||
var titlePart = title ? ' "' + title + '"' : ''; | ||
@@ -312,2 +339,6 @@ return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : '' | ||
function cleanAttribute (attribute) { | ||
return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : '' | ||
} | ||
/** | ||
@@ -553,5 +584,5 @@ * Manages a collection of rules used to convert HTML to Markdown | ||
{ | ||
var JSDOM = require('jsdom').JSDOM; | ||
var domino = require('domino'); | ||
Parser.prototype.parseFromString = function (string) { | ||
return new JSDOM(string).window.document | ||
return domino.createDocument(string) | ||
}; | ||
@@ -603,6 +634,7 @@ } | ||
return ( | ||
['A', 'TH', 'TD', 'IFRAME', 'SCRIPT', 'AUDIO', 'VIDEO'].indexOf(node.nodeName) === -1 && | ||
!isVoid(node) && | ||
!isMeaningfulWhenBlank(node) && | ||
/^\s*$/i.test(node.textContent) && | ||
!isVoid(node) && | ||
!hasVoid(node) | ||
!hasVoid(node) && | ||
!hasMeaningfulWhenBlank(node) | ||
) | ||
@@ -609,0 +641,0 @@ } |
{ | ||
"name": "turndown", | ||
"description": "A library that converts HTML to Markdown", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"author": "Dom Christie", | ||
@@ -10,6 +10,6 @@ "main": "lib/turndown.cjs.js", | ||
"browser": { | ||
"jsdom": false | ||
"domino": false | ||
}, | ||
"dependencies": { | ||
"jsdom": "^16.2.0" | ||
"domino": "^2.1.6" | ||
}, | ||
@@ -16,0 +16,0 @@ "devDependencies": { |
347046
17
10956
+ Addeddomino@^2.1.6
+ Addeddomino@2.1.6(transitive)
- Removedjsdom@^16.2.0
- Removed@tootallnate/once@1.1.2(transitive)
- Removedabab@2.0.6(transitive)
- Removedacorn@7.4.18.11.3(transitive)
- Removedacorn-globals@6.0.0(transitive)
- Removedacorn-walk@7.2.0(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedbrowser-process-hrtime@1.0.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcssom@0.3.80.4.4(transitive)
- Removedcssstyle@2.3.0(transitive)
- Removeddata-urls@2.0.0(transitive)
- Removeddebug@4.3.5(transitive)
- Removeddecimal.js@10.4.3(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddomexception@2.0.1(transitive)
- Removedescodegen@2.1.0(transitive)
- Removedesprima@4.0.1(transitive)
- Removedestraverse@5.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedform-data@3.0.1(transitive)
- Removedhtml-encoding-sniffer@2.0.1(transitive)
- Removedhttp-proxy-agent@4.0.1(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedis-potential-custom-element-name@1.0.1(transitive)
- Removedjsdom@16.7.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.1.2(transitive)
- Removednwsapi@2.2.10(transitive)
- Removedparse5@6.0.1(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedquerystringify@2.2.0(transitive)
- Removedrequires-port@1.0.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsaxes@5.0.1(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsymbol-tree@3.2.4(transitive)
- Removedtough-cookie@4.1.4(transitive)
- Removedtr46@2.1.0(transitive)
- Removeduniversalify@0.2.0(transitive)
- Removedurl-parse@1.5.10(transitive)
- Removedw3c-hr-time@1.0.2(transitive)
- Removedw3c-xmlserializer@2.0.0(transitive)
- Removedwebidl-conversions@5.0.06.1.0(transitive)
- Removedwhatwg-encoding@1.0.5(transitive)
- Removedwhatwg-mimetype@2.3.0(transitive)
- Removedwhatwg-url@8.7.0(transitive)
- Removedws@7.5.9(transitive)
- Removedxml-name-validator@3.0.0(transitive)
- Removedxmlchars@2.2.0(transitive)