Giter Club home page Giter Club logo

bbcode-parser-template's Introduction

bbcode-parser-template

Template system for bbcode-parser.

Getting started

Prerequisites

Installing

npm install @thoughtsunificator/bbcode-parser-template

Usage

Creating a Code

src/codes/b.js

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

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(`<span style="font-weight: bold">Test</span>`)

API

You can read the API by visiting http://bbcode-parser-template.unificator.me.

Example

See https://github.com/thoughtsunificator/bbcode-parser-template-example.

bbcode-parser-template's People

Contributors

thoughtsunificator avatar

Watchers

 avatar  avatar  avatar

bbcode-parser-template's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.