markdown-it-abbr
markdown-it-abbr copied to clipboard
Config object for definitions
I think it'd be nice for the abbreviations and their expanded forms to be defined where the plugin is use()'d as to avoid the complication of handling transclusion per file.
I wrote this for now:
// MarkdownItInjectContent
export default (md, { content, prepend = false } = {}) => {
md.core.ruler.before('normalize', 'inject_content', (state) => {
if (prepend) {
state.src = `${content}\n\n${state.src}`;
} else {
state.src = `${state.src}\n\n${content}`;
}
// Avoid strange errors with npmjs.com/markdown-it-abbr
if (!state.env) {
state.env = {};
}
if (!state.env.references) {
state.env.references = {};
}
return true;
});
};
// Must be before `MarkdownItAbbr`
mdLib.use(MarkdownItInjectContent, {
// Could obviously use `await fs.readFile` here
content: '*[HTML]: HyperText Markup Language',
});
The above code did work in isolation, but has issues when integrating with markdown-it-implicit-figures, so I forked this project to include this issue's request and a fix for #10.