Skip to content

Request For Overriding Footnote Superscript Style #61

@systemcarl

Description

@systemcarl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions