xbbcode-parser
Advanced tools
Comparing version 0.1.2 to 0.2.0
{ | ||
"name": "xbbcode-parser", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Allows you to parse BBCode and to extend the markup to add your own tags.", | ||
@@ -5,0 +5,0 @@ "main": "xbbcode.js", |
@@ -76,1 +76,5 @@ # Extendible-BBCode-Parser | ||
bugs please let me know. | ||
### Adding 'single' tags | ||
Simply do what you had been doing so far, but without providing an closeTag function. |
@@ -86,3 +86,3 @@ /* | ||
* | ||
* LIMITIONS on adding NEW TAGS: | ||
* LIMITATIONS on adding NEW TAGS: | ||
* - Tag names should be alphanumeric (including underscores) and all tags should have an opening tag | ||
@@ -97,2 +97,7 @@ * and a closing tag. | ||
tags = { | ||
'hr': { | ||
openTag: function(params, content) { | ||
return '<hr/>'; | ||
} | ||
}, | ||
"b": { | ||
@@ -567,3 +572,3 @@ openTag: function(params,content) { | ||
for (var ii = 0; ii < tagList.length; ii++) { | ||
if ( tagList[ii] !== "\\*" ) { // the * tag doesn't have an offical closing tag | ||
if ( tagList[ii] !== "\\*" ) { // the * tag doesn't have an official closing tag | ||
closeTagList.push ( "/" + tagList[ii] ); | ||
@@ -663,5 +668,5 @@ } | ||
var processedContent = tags[tagName].noParse ? unprocess(tagContents) : tagContents.replace(bbRegExp, replaceFunct), | ||
openTag = tags[tagName].openTag(tagParams,processedContent), | ||
closeTag = tags[tagName].closeTag(tagParams,processedContent); | ||
openTag = (tags[tagName].openTag) ? tags[tagName].openTag(tagParams,processedContent) : '', | ||
closeTag = (tags[tagName].closeTag) ? tags[tagName].closeTag(tagParams,processedContent) : ''; | ||
if ( tags[tagName].displayContent === false) { | ||
@@ -683,3 +688,3 @@ processedContent = ""; | ||
tag, we must pre-process the input and add in closing tags [/*] for the star tag. | ||
We have a little levaridge in that we know the text we're processing wont contain the <> characters (they have been | ||
We have a little leverage in that we know the text we're processing wont contain the <> characters (they have been | ||
changed into their HTML entity form to prevent XSS and code injection), so we can use those characters as markers to | ||
@@ -713,2 +718,18 @@ help us define boundaries and figure out where to place the [/*] tags. | ||
function fixSingleTags(text) { | ||
for(var k in tags) { | ||
if(!tags[k].closeTag) { | ||
text = text.replaceAll(`[${k}]`, tags[k].openTag()); | ||
} | ||
} | ||
return text; | ||
} | ||
function securityFixes(text) { | ||
return text | ||
.replaceAll("'", '"') | ||
.replaceAll('"', ''') | ||
.replaceAll(';', ';'); | ||
} | ||
function addBbcodeLevels(text) { | ||
@@ -756,2 +777,3 @@ while ( text !== (text = text.replace(pbbRegExp, function(matchStr, tagName, tagParams, tagContents) { | ||
config.text = securityFixes(config.text); | ||
config.text = config.text.replace(/\[/g, "["); // escape ['s that aren't apart of tags | ||
@@ -778,2 +800,4 @@ config.text = config.text.replace(/\]/g, "]"); // escape ['s that aren't apart of tags | ||
ret.html = fixSingleTags(ret.html); | ||
if ( ret.html.indexOf("[") !== -1 || ret.html.indexOf("]") !== -1) { | ||
@@ -780,0 +804,0 @@ errQueue.push("Some tags appear to be misaligned."); |
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
49281
9
1099
80