Skip to content

Commit

Permalink
remark-parse: add list of inline-, block-methods to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 26, 2017
1 parent cd0d437 commit dcfe849
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lerna": "2.0.0",
"mdast-util-assert": "^1.0.0",
"mdast-util-compact": "^1.0.0",
"mdast-zone": "^3.0.1",
"nyc": "^11.0.0",
"remark-preset-wooorm": "^3.0.0",
"tape": "^4.5.1",
Expand Down Expand Up @@ -67,6 +68,7 @@
},
"remarkConfig": {
"plugins": [
"./script/list-of-methods",
"preset-wooorm"
]
}
Expand Down
41 changes: 41 additions & 0 deletions packages/remark-parse/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,63 @@ An object mapping tokenizer names to [tokenizer][]s. These
tokenizers (for example: `fencedCode`, `table`, and `paragraph`) eat
from the start of a value to a line ending.

See `#blockMethods` below for a list of methods that are included by
default.

### `Parser#blockMethods`

Array of `blockTokenizers` names (`string`) specifying the order in
which they run.

<!--methods-block start-->

* `newline`
* `indentedCode`
* `fencedCode`
* `blockquote`
* `atxHeading`
* `thematicBreak`
* `list`
* `setextHeading`
* `html`
* `footnote`
* `definition`
* `table`
* `paragraph`

<!--methods-block end-->

### `Parser#inlineTokenizers`

An object mapping tokenizer names to [tokenizer][]s. These tokenizers
(for example: `url`, `reference`, and `emphasis`) eat from the start
of a value. To increase performance, they depend on [locator][]s.

See `#inlineMethods` below for a list of methods that are included by
default.

### `Parser#inlineMethods`

Array of `inlineTokenizers` names (`string`) specifying the order in
which they run.

<!--methods-inline start-->

* `escape`
* `autoLink`
* `url`
* `html`
* `link`
* `reference`
* `strong`
* `emphasis`
* `deletion`
* `code`
* `break`
* `text`

<!--methods-inline end-->

### `function tokenizer(eat, value, silent)`

```js
Expand Down
36 changes: 36 additions & 0 deletions script/list-of-methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var zone = require('mdast-zone');
var u = require('unist-builder');
var proto = require('../packages/remark-parse').Parser.prototype;

module.exports = listOfMethods;

function listOfMethods() {
return transformer;
}

function transformer(tree) {
zone(tree, 'methods-block', replace('blockMethods'));
zone(tree, 'methods-inline', replace('inlineMethods'));
}

function replace(name) {
var list = proto[name];

return replace;

function replace(start, nodes, end) {
return [
start,
u('list', {ordered: false}, list.map(function (name) {
return u('listItem', [
u('paragraph', [
u('inlineCode', name)
])
]);
})),
end
];
}
}

0 comments on commit dcfe849

Please sign in to comment.