core icon indicating copy to clipboard operation
core copied to clipboard

Explicit ids?

Open xianghongai opened this issue 3 years ago • 16 comments

Clear and concise description of the problem

want to explicitly set the id attribute of headings from the Markdown document, for example to keep them consistent across translations.

Suggested solution

  • https://www.npmjs.com/package/markdown-it-attrs
  • https://github.com/valeriangalliat/markdown-it-anchor#explicit-ids

Alternative

No response

Additional context

No response

xianghongai avatar Jun 14 '22 08:06 xianghongai

## 插入图片示例 {#insert-image}
## Insert Image {#insert-image}

xianghongai avatar Jun 14 '22 08:06 xianghongai

I do think about supporting it, currectly our logic is to apply a default slugify function on title.

@meteorlxy Any suggestion with this one?

Mister-Hope avatar Jun 14 '22 08:06 Mister-Hope

I've noticed this before in some docs translation repo. I think users could use it with extendsMarkdown by themselves as needed.

Might be a good idea to integrate it by default.

meteorlxy avatar Jun 14 '22 08:06 meteorlxy

I've noticed this before in some docs translation repo. I think users could use it with extendsMarkdown by themselves as needed.

Nope, I think that's hard. I was trying to build one long time ago, but I met some issues.

Mister-Hope avatar Jun 14 '22 09:06 Mister-Hope

Anyway I will relook into this, and if it can be solved at users side, I will add this to vuepress-plugin-md-enhance, if some lines must be changed at @vuepress/markdown I will open a PR to add this as a built-in function. Ok to you? @meteorlxy

Mister-Hope avatar Jun 14 '22 09:06 Mister-Hope

Nope, I think that's hard. I was trying to build one long time ago, but I met some issues.

Well, it seems to work well here with a rough test 🤔 .

meteorlxy avatar Jun 14 '22 09:06 meteorlxy

Use vuepress-plugin-md-enhance@next, and enable attrs.

Mister-Hope avatar Jun 15 '22 00:06 Mister-Hope

Don't close issue too casually. We could consider to integrate it .

meteorlxy avatar Jun 15 '22 03:06 meteorlxy

Emm, I don't think this is a core feature though. We EVEN do not add full support for gfm, so what makes you reconsider this one?🧐

Mister-Hope avatar Jun 15 '22 03:06 Mister-Hope

Also, the original markdown-it-attrs should be modified to only suppor heading ids, or it may breaks peoples markdown content.

After I support attrs yesterday, I already received a report saying that his content is parsed incorrectly today hours ago, and some content are parsed as attrs.

Anyway if you do think that we need heading ids, I can open a pr to support that.

Mister-Hope avatar Jun 15 '22 03:06 Mister-Hope

Meanwhile, I would also consider features like link-checking or gfm are more important than this one. If you still want to enlarge core markdown features, I would suggest adding these as well.

Mister-Hope avatar Jun 15 '22 03:06 Mister-Hope

what makes you reconsider this one?

As we are providing i18n support out-of-the-box, it's helpful when switching languages and keep the current hash.

meteorlxy avatar Jun 15 '22 03:06 meteorlxy

link-checking or gfm

Any suggestions about the above one? Some users complain that they can't keep markdown file as is from github markdown to our tool.

Also the image link discussed in the other issue is also a big problem.

Mister-Hope avatar Jun 15 '22 03:06 Mister-Hope

## 插入图片示例 <!-- #insert-image -->

## Insert Image <!-- #insert-image -->

This way of marking does not break the Markdown syntax.

xianghongai avatar Jun 15 '22 05:06 xianghongai

Nice idea, it also does not break tools like prettier or markdownlint.

Actually we can just keep that syntax, becase we can use \{ to prevent markdown attrs plugin to parse.

The problem is that it adds support in many places, see https://vuepress-theme-hope.github.io/v2/md-enhance/guide/attrs.html#demo.

If we include it as is, the chance breaking user content might be a little high, as it's possible for user content to include {xxx}

Mister-Hope avatar Jun 15 '22 05:06 Mister-Hope

Update here, md-enhance already support attrs. See https://vuepress-theme-hope.github.io/v2/md-enhance/guide/attrs.html#demo to use this.

So if this needs to be added in core just copy my code.

Mister-Hope avatar Aug 17 '22 14:08 Mister-Hope