shortcode-tree
Advanced tools
Comparing version 1.4.8 to 1.4.9
@@ -102,2 +102,36 @@ 'use strict'; | ||
return textContent; | ||
}, | ||
generateHtmlEquivalent: function generateHtmlEquivalent(input) { | ||
var treeRootNode = this.parse(input); | ||
var textContent = ""; | ||
var fnTraverseNodeForContent = function fnTraverseNodeForContent(node) { | ||
var nodeChildText = null; | ||
if (node instanceof TextNode) { | ||
nodeChildText = node.text; | ||
} else if (node instanceof ShortcodeNode) { | ||
if (node.children.length) { | ||
var _tvChildContent = ''; | ||
node.children.forEach(function (node) { | ||
_tvChildContent += fnTraverseNodeForContent(node); | ||
}); | ||
if (node.shortcode) { | ||
node.shortcode.content = _tvChildContent; | ||
nodeChildText = node.shortcode.stringifyAsHtml(); | ||
} else { | ||
nodeChildText = _tvChildContent; | ||
} | ||
} else { | ||
// Topmost node with no children | ||
nodeChildText = node.shortcode.stringifyAsHtml(); | ||
} | ||
} | ||
return nodeChildText; | ||
}; | ||
return fnTraverseNodeForContent(treeRootNode); | ||
} | ||
@@ -104,0 +138,0 @@ }; |
{ | ||
"name": "shortcode-tree", | ||
"version": "1.4.8", | ||
"version": "1.4.9", | ||
"description": "Parser library for reading short codes (BB codes) into a tree structure", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -131,2 +131,9 @@ let ShortcodeTree = require('../src').ShortcodeTree; | ||
}); | ||
it('generates html equiv text', function () { | ||
let testInput = `text [div][strong]Hi[/strong][img/]text[div][strong]sub[/strong][/div][/div] text`; | ||
let html = ShortcodeTree.generateHtmlEquivalent(testInput); | ||
expect(html).to.equal("text <div><strong>Hi</strong><img/>text<div><strong>sub</strong></div></div> text"); | ||
}); | ||
}); | ||
@@ -133,0 +140,0 @@ |
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
77779
1367