remark-shortcodes
Advanced tools
Comparing version 0.2.1 to 0.3.0
12
index.js
@@ -46,11 +46,11 @@ "use strict"; | ||
var endBlock = (options || {}).endBlock || "]]"; | ||
var inlineMode = (options || {}).inlineMode || false; | ||
if (isRemarkParser(this.Parser)) { | ||
var parser = this.Parser.prototype; | ||
parser.blockTokenizers.shortcode = shortcodeTokenizer; | ||
parser.blockMethods.splice( | ||
parser.blockMethods.indexOf("html"), | ||
0, | ||
"shortcode" | ||
); | ||
var tokenizers = inlineMode ? parser.inlineTokenizers : parser.blockTokenizers; | ||
var methods = inlineMode ? parser.inlineMethods : parser.blockMethods; | ||
tokenizers.shortcode = shortcodeTokenizer; | ||
methods.splice(methods.indexOf("html"), 0, "shortcode"); | ||
} | ||
@@ -57,0 +57,0 @@ if (isRemarkCompiler(this.Compiler)) { |
{ | ||
"name": "remark-shortcodes", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Shortcode parser plugin for Remark", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -150,2 +150,46 @@ # remark-shortcodes [![NPM Package][npm-package-badge]][npm-package] [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
Say `example3.js` looks as follows: | ||
```javascript | ||
var unified = require('unified'); | ||
var parse = require('remark-parse'); | ||
var shortcodes = require('remark-shortcodes'); | ||
var markdown = 'Example paragraph {{> MailchimpForm id="chfk2" <}}' | ||
var tree = unified() | ||
.use(parse) | ||
// Plugin inserted below, with custom options for start/end blocks. | ||
.use(shortcodes, {startBlock: "{{>", endBlock: "<}}", inlineMode: true}) | ||
// Turn off position output for legibility below. | ||
.data('settings', {position: false}) | ||
.parse(markdown); | ||
console.dir(tree, {depth: null}); | ||
``` | ||
Running `node example3` yields: | ||
```json | ||
{ | ||
"type": "root", | ||
"children": [ | ||
{ | ||
"type": "paragraph", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "Example paragraph " | ||
}, | ||
{ | ||
"type": "shortcode", | ||
"identifier": "MailchimpForm", | ||
"attributes": { "id": "chfk2" } | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
## API | ||
@@ -159,2 +203,3 @@ | ||
- `endBlock`: the end block to look for. Default: `]]`. | ||
- `inlineMode`: shortcodes will be parsed inline rather than in block mode. Default: `false`. | ||
@@ -180,3 +225,4 @@ NB: Be careful when using custom start/end blocks, your choices | ||
- Commit and tag with version number (`git tag -a v0.1.x -m v0.1.x`) | ||
- Push | ||
- git push --tags | ||
- Travis setup handles the rest | ||
@@ -183,0 +229,0 @@ ## License |
14276
259
157