A crude BBCode parser that outputs a string that contains HTML elements.
Do not use it on in a production/critical environment, it messes up often and easily.
Just add the js file in your page and call the function processText(rawText)
with your raw BBCode as the rawText
argument.
And you will either get the parsed HTML code or an error string that follows this format: ERROR: <message>
.
Check "demo.html" for an example, or "this link (UNAVAILABLE)" for a live demo.
Go to the "Specification page" to read it.
You can easily add custom tags by modifying the bbElements
constant.
It is an array of objects that follow this structure:
Field | Type | Description |
tags | String[] | Array that contains the BBCode tags that refer to this element. |
htmlElement | String | The HTML element that will be used for opening and closing this tag. |
htmlElementDefaultParams | String | Optional String that is added to the opening HTML element if the `parameters` field is undefined, null or empty. |
parameters | Parameter[] | Optional array of Parameter objects that define all the possible parameters for the tag. |
And here is the Parameter structure:
Field | Type | Description |
name | String[] | Array of strings that correspond to this parameter. |
isRequired | Boolean |
Indicates wether or not this parameter is required to parse this tag. Returns an error message if the parameter is not declared in the BBCode. |
isDefault | Boolean |
Indicates wether or not this parameter is the one that will be parsed if it is joined to the tag like this: `[tag=val]`. Returns an error message if a parameter like this is used an no parameter is set as the default one. |
isTagParameter | Boolean | Indicates wether or not the value of this parameter should be put inside the final HTML element as a value like: <a arg1="val1">. |
tagValueKey | String | Used as the parameter key in the HTML element is `isTagParameter` is set to true. |
tagValueContentPrefix | String | ??? |
tagValueContentSuffix | String | ??? |