Movatterモバイル変換


[0]ホーム

URL:


  • Preparing search index...
  • The search index is not available
bbcode-ast

Class Parser

Constructors

constructor

  • newParser(supportedTagNames,caseSensitive?,lenient?):Parser
  • Parameters

    • supportedTagNames:string[]
    • OptionalcaseSensitive:boolean
    • Optionallenient:boolean

    ReturnsParser

Properties

caseSensitive

caseSensitive:boolean

Whether the parser should be case-sensitive or not regarding tag names andsupportedTagNames.

lenient

lenient:boolean

Is more lenient about closing tags and mismatched tags. Instead of throwing an error, it will turn the entire nodeinto aTextNode with the text of the entire node.

supportedTagNames

supportedTagNames:string[]

The list of supported tag names. Any tags that are not in this list will be treated like text.

Methods

PrivategetNameRespectingSensitivity

parse

  • parse(text):RootNode
  • Convert a chunk of BBCode to aRootNode.

    Parameters

    • text:string

      The chunk of BBCode to convert.

    ReturnsRootNode

    TheRootNode representing the BBCode.

    Throws

    If the BBCode is not valid (missing a closing tag).

    Example: Basic Example

    constparsed =parser.parse("[b]Hello, world![/b]");
    console.log(parsed.toString());// [b]Hello, world![/b]
    console.log(parsed.nodeTree());

    // RootNode {
    // Node [b] {
    // TextNode {
    // Hello, world!
    // }
    // }
    // }

    Example: Example with Attributes

    constparsed =parser.parse("[b][i]Hi![/i][/b][img width=100 height=100]https://example.com/image.png[/img]");
    console.log(parsed.toString());// [b][i]Hi![/i][/b][img width=100 height=100]https://example.com/image.png[/img]
    console.log(parsed.nodeTree());

    // RootNode {
    // Node [b] {
    // Node [i] {
    // TextNode {
    // Hi!
    // }
    // }
    // }
    // Node [img] (width=100, height=100) {
    // TextNode {
    // https://example.com/image.png
    // }
    // }
    // }

    Example: Complex Example

    constparsed =parser.parse('[size=50][quote=JohnDoe message=1]Hello, world![/quote][/size][img alt="World said hi!" width=100 height=100]https://example.com/image.png[/img]');
    console.log(parsed.toString());// [size=50][quote=JohnDoe message=1]Hello, world![/quote][/size][img alt="World said hi!" width=100 height=100]https://example.com/image.png[/img]
    console.log(parsed.nodeTree());

    // RootNode {
    // Node [size] {
    // Node [quote] (JohnDoe, message=1) {
    // TextNode {
    // Hello, world!
    // }
    // }
    // }
    // Node [img] (alt="World said hi!", width=100, height=100) {
    // TextNode {
    // https://example.com/image.png
    // }
    // }
    // }

Settings

Member Visibility

Theme

On This Page

Generated usingTypeDoc


[8]ページ先頭

©2009-2025 Movatter.jp