Package Exports
- bbcode-parser
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bbcode-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Usage:
var BBCodeParser = require('bbcode-parser');
var parser = new BBCodeParser(BBCodeParser.defaultTags());
var html = parser.parseString('[b]Bold text[/b]');You can also define your own tags:
var bbTags = {};
//Simple tag. A simple tag means that the generated HTML will be <tagName>content</tagName>
bbTags["b"] = new BBTag("b", true, false, false);
//Tag with a custom generator.
bbTags["img"] = new BBTag("img", true, false, false, function (tag, content, attr) {
return "<img src=\"" + content + "\" />";
});
//Tag with a custom generator + attributes
bbTags["url"] = new BBTag("url", true, false, false, function (tag, content, attr) {
var link = content;
if (attr["site"] != undefined) {
link = escapeHTML(attr["site"]);
}
if (!startsWith(link, "http://") && !startsWith(link, "https://")) {
link = "http://" + link;
}
return "<a href=\"" + link + "\" target=\"_blank\">" + content + "</a>";
});
//A tag that doesn't support nested tags. Useful when implementing code highlighting.
bbTags["code"] = new BBTag("code", true, false, true, function (tag, content, attr) {
return "<code>" + content + "</code>";
});
var parser = new BBCodeParser(bbTags);