0.2.19 • Published 6 months ago
@tryghost/mg-shortcodes v0.2.19
Shortcodes
A barebones shortcode parser that handles edge cases.
Install
npm install @tryghost/mg-shortcodes --save
or
yarn add @tryghost/mg-shortcodes
Usage
// Import the class
import Shortcodes from '@tryghost/mg-shortcodes';
// Create a new instance
const shortcodes = new Shortcodes();
// Handle [link] shortcodes
shortcodes.add('link', ({attrs, content}) => {
return `<a href="${attrs.url}">${content}</a>`;
});
// [abc color="red"]<p>Full post</p>[def]<p>Free excerpt</p>[/abc]
shortcodes.addWitSplit('abc', 'def', 0, ({content}) => {
return content; // <p>Full post</p>
});
// Unwrap [block] shortcodes
shortcodes.unwrap('block');
// You can add & unwrap as many shortcodes as you like. The order is not important.
const content = `[block][link url="https://example.com"]Hello[/link][/block]`;
// Parse the content and return the updated content
const updatedContent = shortcodes.parse(content);
// <a href="https://example.com">Hello</a>
Develop
This is a mono repository, managed with lerna.
Follow the instructions for the top-level repo.
1. git clone
this repo & cd
into it as usual
2. Run yarn
to install top-level dependencies.
Run
yarn dev
Test
yarn lint
run just eslintyarn test
run lint and testsyarn benchmark
run benchmarks
Copyright & License
Copyright (c) 2013-2023 Ghost Foundation - Released under the MIT license.
0.2.19
6 months ago
0.2.18
1 year ago
0.2.17
1 year ago
0.2.16
1 year ago
0.2.15
2 years ago
0.2.14
2 years ago
0.2.13
2 years ago
0.2.12
2 years ago
0.2.11
2 years ago
0.2.10
2 years ago
0.2.9
2 years ago
0.2.8
2 years ago
0.2.7
2 years ago
0.2.6
2 years ago
0.2.5
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.2.4
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago