shortcode-tree
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "shortcode-tree", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Parser library for reading short codes (BB codes) into a tree structure", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -17,3 +17,3 @@ let ShortcodeParser = require('./shortcode-parser'); | ||
// Worse yet, in the case of malformatted shortcodes, this won't work reliably at all. That's a TODO: Figure out how to deal with malformatted input elegantly | ||
const regex = /\[(.*)\]([\S\s]*)\[\/(.*)\]/g; | ||
const regex = /\[(.*)(\]([\S\s]*)\[\/(.*)\]|\/\])/g; | ||
@@ -20,0 +20,0 @@ let match; |
@@ -196,8 +196,8 @@ let fs = require('fs'); | ||
shortcode.content = input.substr(openBlockStartIdx + openBlockTextFull.length, (input.length - openBlockTextFull.length - closingTagExpected.length - offsetFromEnd)); | ||
shortcode.codeText = input.substr(openBlockStartIdx, input.length - offsetFromEnd); | ||
} else { | ||
shortcode.content = null; | ||
shortcode.codeText = input.substr(openBlockStartIdx, openBlockTextFull.length); | ||
} | ||
shortcode.codeText = input.substr(openBlockStartIdx, input.length - offsetFromEnd); | ||
return shortcode; | ||
@@ -204,0 +204,0 @@ } |
@@ -25,2 +25,11 @@ let ShortcodeExtractor = require('../src').ShortcodeExtractor; | ||
it('extracts a self-closing shortcode with text surrounding it', function () { | ||
let testInput = "Check out [img src=abc.jpg/], a cool image"; | ||
let expectedOutput = [new Shortcode("img", null, {"src": "abc.jpg"}, true, "[img src=abc.jpg/]", 10)]; | ||
let actualOutput = ShortcodeExtractor.extractShortcodes(testInput) || null; | ||
expect(actualOutput).to.deep.equal(expectedOutput); | ||
}); | ||
it('extracts multiple simple shortcodes on the same level', function () { | ||
@@ -27,0 +36,0 @@ let testInput = "[b]boldest text[/b][i]bats[/i]"; |
@@ -97,2 +97,10 @@ let ShortcodeParser = require('../src').ShortcodeParser; | ||
it('calculates the correct code text for self-closing tags in an offset string', function () { | ||
let testInput = `edge case [antics/] are here`; | ||
let expectedOutput = new Shortcode("antics", null, {}, true, "[antics/]", 10); | ||
let actualOutput = ShortcodeParser.parseShortcode(testInput, options) || null; | ||
expect(actualOutput).to.deep.equal(expectedOutput); | ||
}); | ||
it('throws an error for malformatted input: missing opening tag', function () { | ||
@@ -99,0 +107,0 @@ let testInput = `no opening tag`; |
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
27977
424