Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the order of use of markdown-it plugins #391

Closed
3 tasks done
QC-L opened this issue Sep 10, 2021 · 3 comments · Fixed by #393
Closed
3 tasks done

About the order of use of markdown-it plugins #391

QC-L opened this issue Sep 10, 2021 · 3 comments · Fixed by #393
Labels
bug: pending triage Maybe a bug, waiting for confirmation

Comments

@QC-L
Copy link
Contributor

QC-L commented Sep 10, 2021

Describe the bug

When localizing documents, it is necessary to retain the original anchor points, e.g.

# Getting Started

in Chinese

# 快速开始 {#getting-started}

In this case, I need to use markdown-it-attrs, but the source code uses markdown-it-anchor, and attrs needs to be executed before anchor.

markdown-it-anchor is described in the documentation

markdown-it-anchor is designed to reuse any existing id, making markdown-it-attrs a perfect fit for this use case. Make sure to load it before markdown-it-anchor!

Reproduction

None

Expected behavior

None

System Info

None

Additional context

I think there are two solutions:

  1. add markdown-it-attrs to the source code
  2. add a pre-selection for loading plugins
  // pre config
  if (options.preConfig) {
    options.preConfig(md)
  }

  // custom plugins
  md.use(componentPlugin)
    .use(highlightLinePlugin)
    .use(preWrapperPlugin)
    .use(snippetPlugin, srcDir)
    .use(hoistPlugin)
    .use(containerPlugin)
    .use(extractHeaderPlugin)
    .use(linkPlugin, {
      target: '_blank',
      rel: 'noopener noreferrer',
      ...options.externalLinks
    })

    // 3rd party plugins
    .use(anchor, {
      slugify,
      permalink: anchor.permalink.ariaHidden({}),
      ...options.anchor
    })
    .use(toc, {
      slugify,
      includeLevel: [2, 3],
      format: parseHeader,
      ...options.toc
    })
    .use(emoji)
	// ...

  // apply user config
  if (options.config) {
    options.config(md)
  }

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@QC-L QC-L added the bug: pending triage Maybe a bug, waiting for confirmation label Sep 10, 2021
@antfu
Copy link
Member

antfu commented Sep 10, 2021

I would vote for including markdown-it-attrs as a part of vitepress giving it's quite a common use case for translated documentation.

@QC-L
Copy link
Contributor Author

QC-L commented Sep 10, 2021

Okay, then I will go to modify PR #392

@QC-L
Copy link
Contributor Author

QC-L commented Sep 11, 2021

Okay, then I will go to modify PR #392

Done, please see #393

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: pending triage Maybe a bug, waiting for confirmation
Projects
None yet
2 participants