An open API service indexing awesome lists of open source software.

https://github.com/aziascreations/extended-bbcode-parser

A crude BBCode parser that outputs a string that contains HTML elements
https://github.com/aziascreations/extended-bbcode-parser

bbcode bbcode-parser unsafe

Last synced: about 2 months ago
JSON representation

A crude BBCode parser that outputs a string that contains HTML elements

Awesome Lists containing this project

README

          

# Extended BBCode Parser

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.

## Usage

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: `.

Check "[demo.html](demo.html)" for an example, or "[this link (UNAVAILABLE)]()" for a live demo.

## Specification

Go to the "[Specification page](specification.md)" to read it.

## Custom tags

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
???

## License

[Unlicense](LICENSE)