shortcode-tree
Advanced tools
Comparing version 1.4.4 to 1.4.5
@@ -58,8 +58,4 @@ "use strict"; | ||
var predictedAsSelfClosing = input.indexOf(closingTagExpected) === -1; | ||
if (predictedAsSelfClosing) { | ||
shortcode.isSelfClosing = true; | ||
} else { | ||
shortcode.isSelfClosing = false; | ||
if (options.predictSelfClosing) { | ||
shortcode.isSelfClosing = input.indexOf(closingTagExpected) === -1; | ||
} | ||
@@ -127,4 +123,8 @@ | ||
var blockName = nextBlockInfo.name; | ||
// console.log(nextBlockInfo); | ||
if (options.predictSelfClosing) { | ||
var nextClosingTagExpected = "[/" + blockName + "]"; | ||
nextBlockInfo.isSelfClosing = bufferRemainder.indexOf(nextClosingTagExpected) === -1; | ||
} | ||
if (!nextBlockInfo.isSelfClosing) { | ||
@@ -307,6 +307,8 @@ stackLevel++; | ||
if (!shortcode.isSelfClosing && options.selfClosingTags.indexOf(shortcode.name) > -1) { | ||
// Explicitly listed in options as a naughty, misbehaving self-closing tag | ||
// This is one unfortunate scenario where we simply cannot parse blindly :-( | ||
shortcode.isSelfClosing = true; | ||
if (!options.predictSelfClosing) { | ||
if (!shortcode.isSelfClosing && options.selfClosingTags.indexOf(shortcode.name) > -1) { | ||
// Explicitly listed in options as a naughty, misbehaving self-closing tag | ||
// This is one unfortunate scenario where we simply cannot parse blindly :-( | ||
shortcode.isSelfClosing = true; | ||
} | ||
} | ||
@@ -366,5 +368,13 @@ } | ||
*/ | ||
selfClosingTags: [] | ||
selfClosingTags: [], | ||
/** | ||
* If enabled, self-closing tags will be predicted by checking if any closing tags can be found. | ||
* This generally improves stability, but will break horribly if your tags are only "sometimes" self-closing. | ||
* | ||
* @type boolean | ||
*/ | ||
predictSelfClosing: true | ||
}; | ||
module.exports = ShortcodeParser; |
{ | ||
"name": "shortcode-tree", | ||
"version": "1.4.4", | ||
"version": "1.4.5", | ||
"description": "Parser library for reading short codes (BB codes) into a tree structure", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -153,3 +153,4 @@ # shortcode-tree | ||
| `precise` | boolean | `false` | If things aren't working as expected, enable this for deep recursive parsing. Reduces performance exponentially. | | ||
| `selfClosingTags` | array | `[]` | You can specify a list of tags that should always be treated as self-closing. Needed when they don't use the "[selfcloser/]" syntax. | | ||
| `selfClosingTags` | array | `[]` | You can specify a list of tags that should always be treated as self-closing. Needed when they don't use the "[selfcloser/]" syntax. | | ||
| `predictSelfClosing` | bool | `true` | If enabled, self-closing tags will be predicted by checking if any closing tags can be found anywhere in the input buffer. Improves stability in most situations, but breaks if your tags are "sometimes" self closing. | | ||
@@ -156,0 +157,0 @@ The default options are defined in `ShortcodeParser.DEFAULT_OPTIONS`. |
@@ -121,2 +121,12 @@ let ShortcodeTree = require('../src').ShortcodeTree; | ||
}); | ||
it('parses nested, self-closing tags with inconsistent syntax, and without options entry, correctly (prediction)', function () { | ||
let testInput = `[vc_row_inner][mk_image_slideshow][/vc_row_inner]`; | ||
let parsed = ShortcodeTree.parse(testInput); | ||
expect(parsed.children.length).to.equal(1); | ||
let columnNode = parsed.children[0]; | ||
expect(columnNode.children.length).to.equal(1); | ||
}); | ||
}); | ||
@@ -123,0 +133,0 @@ |
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
69346
1211
198