@crystallize/content-chunk
Advanced tools
Comparing version 0.5.4 to 0.5.5
@@ -0,1 +1,8 @@ | ||
<a name="0.5.5"></a> | ||
## <small>0.5.5 (2018-05-30)</small> | ||
* Small tweak to not allow empty inline elements as children of certain elements ([2eae4ca](https://github.com/snowballdigital/crystallize-content-chunk/commit/2eae4ca)) | ||
<a name="0.5.4"></a> | ||
@@ -2,0 +9,0 @@ ## <small>0.5.4 (2018-05-30)</small> |
const { fromHTML } = require('./src'); | ||
console.log( | ||
fromHTML(` | ||
<p>sasd</p> | ||
<p>asd</p>@ | ||
`) | ||
); | ||
console.log(fromHTML(`<p>hello <i>you</i> <i>dude</i></p>`)); |
{ | ||
"name": "@crystallize/content-chunk", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "Validation and parsing for CCC", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -56,2 +56,19 @@ const parse5 = require('parse5'); | ||
const nodeTypesThatCannotHaveDirectTextChildren = 'ul ol table thead tbody tfoot tr th td img'.split( | ||
' ' | ||
); | ||
function nodeHasContent(node) { | ||
if (node.nodeName === '#text') { | ||
if ( | ||
nodeTypesThatCannotHaveDirectTextChildren.includes( | ||
node.parentNode.nodeName | ||
) | ||
) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function chunkHasContent(chunk) { | ||
@@ -94,2 +111,3 @@ // Empty, inline chunks | ||
chunk.children = Array.from(node.childNodes) | ||
.filter(nodeHasContent) | ||
.map(parseChunk) | ||
@@ -96,0 +114,0 @@ .filter(chunkHasContent); |
Sorry, the diff of this file is too big to display
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
706728
2591