# bbcode-parser

> An extensibile BBCode parser for Node.js and browser

Latest version **1.0.10** (published 2015-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install bbcode-parser
pnpm add bbcode-parser
yarn add bbcode-parser
bun add bbcode-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2015-08-22 |
| First published | 2014-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 34 |
| Author | Anton Jansson |
| Maintainers | svenslaggare |
| Keywords | bbcode, bbcode parser |

## Links

- npm: https://www.npmjs.com/package/bbcode-parser
- Repository: https://github.com/svenslaggare/BBCodeParser
- Issues: https://github.com/svenslaggare/BBCodeParser/issues
- npm.io page: https://npm.io/package/bbcode-parser

## Recent versions

- 1.0.10 (latest) — 2015-08-22
- 1.0.9 — 2015-07-28
- 1.0.8 — 2015-06-23
- 1.0.7 — 2015-05-10
- 1.0.6 — 2014-07-01
- 1.0.5 — 2014-06-28
- 1.0.4 — 2014-06-28
- 1.0.3 — 2014-06-26
- 1.0.2 — 2014-06-26
- 1.0.1 — 2014-06-26
- 1.0.0 — 2014-06-26

## 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 BBTag = require('bbcode-parser/bbTag');

var bbTags = {};

//Simple tag. A simple tag means that the generated HTML will be <tagName>content</tagName>
bbTags["b"] = BBTag.createSimpleTag("b");

//Tag with a custom generator.
bbTags["img"] = BBTag.createTag("img", function (tag, content, attr) {
	return "<img src=\"" + content + "\" />";
});

//Tag with a custom generator + attributes
bbTags["url"] = BBTag.createTag("url", function (tag, content, attr) {
	var link = content;

	if (attr["site"] != undefined) {
		link = BBCodeParser.escapeHTML(attr["site"]);
 	}

	if (!BBCodeParser.startsWith(link, "http://") && !BBCodeParser.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);
```

<b>BBTag constructor:</b>
* tagName: The name of the tag.
* insertLineBreaks: Indicates if the tag inserts line breaks (\n -> `<br>`) in the content.
* suppressLineBreaks: Suppresses line breaks for any nested tag.
* noNesting: If the tags doesn't support nested tags.
* tagGenerator: The HTML generator for the tag. If not supplied the default one is used: `<tagName>content</tagName>`.

## [Documentation](https://github.com/svenslaggare/BBCodeParser/wiki/Documentation)

---
_Source: https://npm.io/package/bbcode-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
