Socket
Socket
Sign inDemoInstall

shortcode-tree

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shortcode-tree

Parser library for reading short codes (BB codes) into a tree structure


Version published
Weekly downloads
36
decreased by-18.18%
Maintainers
1
Weekly downloads
 
Created
Source

Shortcode parser library

Introduction

shortcode-tree provides generic parsing functionality for text containing short codes (also known as bb codes).

This library does not convert short codes to HTML (like many others do), but it converts generic shortcode/HTML input to pure JavaScript objects.

No set up is required, and you do not need to pre-define a list of shortcodes.

Example:

ShortcodeParser.parseShortcode('[image id=123 src="bla.jpg" align="center"/]');

Result:

Shortcode {
     name: 'image',
     content: null,
     properties: { id: '123', src: 'bla.jpg', align: 'center' },
     isSelfClosing: true }

Features

  • Parse individual BB code tags
  • Supports self-closing tags
  • Supports tag properties, with or without string literals and escape characters

Installation

Installation with npm:

npm install shortcode-tree --save

Usage

Parsing a single short code

To parse an individual short code, use the ShortcodeParser class:

let ShortcodeParser = require('shortcode-tree/shortcode-parser');

let parsed = ShortcodeParser.parseShortcode("[b]example input[/b]");

The parseShortcode method returns a Shortcode object with the following properties:

PropertyTypeDescription
namestringTag name
propertiesobjectKey/value object with property values indexed by their name
contentstring or nullThe raw, unparsed content of the tag. May contain HTML and other short codes. NULL for self-closing tags.
isSelfClosingboolIndicates whether this is a self-closing tag without any content.

FAQs

Package last updated on 17 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc