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

Request For Overriding Footnote Superscript Style

Open systemcarl opened this issue 3 months ago • 0 comments

The markdown-it-footnote renderer "rules" don't treat token attributes the same as the base markdown-it renderer.

For example, customizing the base link rendering, you can simply add an attribute:

function link(
  tokens : Tokens,
  idx : number,
  options : Options,
  env : unknown,
  self : Renderer,
) {
  tokens[idx]?.attrPush(['class', 'text typography-link']);
  return self.renderToken(tokens, idx, options);
}

The best way I've found to achieve this with a footnote reference is:

function footnote(
  tokens : Tokens,
  idx : number,
  options : Options,
  env : unknown,
  self : Renderer,
) {
  const rendered = defaultFootnoteRender
    ? defaultFootnoteRender(tokens, idx, options, env, self)
    : '';
  return rendered.replace(
    'class="footnote-ref"',
    'class="footnote-ref text typography-link typography-ref"',
  );
}

This feels flimsy, and the only alternative I can see is just re-implementing the whole renderer bypassing the plugin all together.

Could we replicate the base behavior in this plugin? Of course there are some limitations: the footnote-ref class an d#fn<number> id need to be respected. However, there's surely a way to conditionally apply token attributes to have a nice outcome.

I'm happy to implement if there's a API specification or strategy to action.

systemcarl avatar Nov 07 '25 02:11 systemcarl