0.1.2 • Published 5 years ago

@hewes/shortcode v0.1.2

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

GitHub GitHub tag (latest by date) npm (scoped) node-current (scoped)

A Simple ShortCode Parser

Tokenize a string to an AST (sic) of shortcode/text nodes

When rendering an AST of "content" you end up with text nodes, that may contain so called "shortcodes". You would like to handle these shortcodes differently than text nodes. You can use this to parse the text node into text and shortcode nodes to continue the rendering.

Features

  • Attribute support
    • String attribute values (i.e. quoted string value)
    • Number attribute values (i.e. unquoted number value)
    • Boolean attribute values (i.e. unquoted boolean value)
      • Default Boolean value (i.e. without a value is true)
  • Customizable start/end tags

Usage

Install

npm install @hewes/shortcode

Use

import { parse } from "@hewes/shortcode"

const nodes = parse("[shortcode]");

Produces

[
  {
    "type": "shortcode",
    "token": "[shortcode]",
    "name": "shortcode"
  }
]

Examples

See Examples

Credits