@hewes/shortcode

v0.1.2
A simple shortcode parser

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

npm i @hewes/shortcode

Metadata

  • ISC
  • >=10
  • Aubrey Hewes
  • released 12/29/2020

Downloads

Maintainers