https://github.com/thoughtsunificator/bbcode-parser-template
Template system for bbcode-parser
https://github.com/thoughtsunificator/bbcode-parser-template
bbcode-parser template
Last synced: 5 months ago
JSON representation
Template system for bbcode-parser
- Host: GitHub
- URL: https://github.com/thoughtsunificator/bbcode-parser-template
- Owner: thoughtsunificator
- License: mit
- Created: 2021-06-16T09:11:33.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-15T14:10:23.000Z (almost 3 years ago)
- Last Synced: 2026-01-12T19:10:41.704Z (5 months ago)
- Topics: bbcode-parser, template
- Language: JavaScript
- Homepage: http://bbcode-parser-template.unificator.me
- Size: 1.32 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bbcode-parser-template
Template system for [bbcode-parser](https://github.com/thoughtsunificator/bbcode-parser).
## Getting started
### Prerequisites
- [bbcode-parser](https://github.com/thoughtsunificator/bbcode-parser)
### Installing
``npm install @thoughtsunificator/bbcode-parser-template``
### Usage
#### Creating a Code
``src/codes/b.js``
```javascript
import { Code } from '@thoughtsunificator/bbcode-parser-template'
import { BBElement } from '@thoughtsunificator/bbcode-parser'
export default class extends Code {
/**
* @readonly
* @type {string}
*/
static tagName = "b"
/**
* @param {Node} node
* @returns {boolean}
*/
static testNode(node) {
return node.nodeName === "SPAN" && node.style.fontWeight === "bold"
}
/**
* @param {Conversion} conversion
* @returns {BBNode}
*/
static createBBNode(conversion) {
const bbNode = new BBElement("b")
return bbNode
}
/**
* @param {Conversion} conversion
* @returns {Node}
*/
static createNode(conversion) {
const node = document.createElement("span")
node.style.fontWeight = "bold"
return node
}
}
```
#### Converting BBCode to HTML and vice versa
``src/app.js``
```javascript
import { Template } from "../lib/bbcode-parser-template/index.js"
import b from "./codes/b.js"
const template = new Template([b], document)
console.log(Template.toHTML("[b]Test[/b]")
console.log(Template.toBBCode(`Test`)
```
### API
You can read the API by visiting [http://bbcode-parser-template.unificator.me](http://bbcode-parser-template.unificator.me).
## Example
See [https://github.com/thoughtsunificator/bbcode-parser-template-example](https://github.com/thoughtsunificator/bbcode-parser-template-example).