markdown-it-abbr icon indicating copy to clipboard operation
markdown-it-abbr copied to clipboard

Config object for definitions

Open stevenvachon opened this issue 10 months ago • 2 comments

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.

stevenvachon avatar Mar 14 '25 02:03 stevenvachon

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',
});

stevenvachon avatar Apr 10 '25 18:04 stevenvachon

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.

stevenvachon avatar Apr 10 '25 19:04 stevenvachon