This plug-in adds a grabit
rule that captures the current StateCore of the
MarkdownIt
instance that is parsing the document.
The grabit
rule is added before the normalize
rule. The only job is to grab
the current state. This state we use later to find all the code fragments and
weave them together.
I couldn't find clearly what the rule function should return. To me it is
currently unclear what the difference is between returning false
and returning
true
.
Based on other rules I opted to return false
, as I am assuming that it means
that the next rule is allowed to work on the state and token stream.
import MarkdownIt = require('markdown-it');
import Core = require('markdown-it/lib/parser_core');
export function grabberPlugin(md : MarkdownIt) {
const grabit : Core.RuleCore = state => {
if (state.env) {
state.env.gstate = state;
}
return false;
};
md.core.ruler.before('normalize', 'grabit', grabit);
};