【问题标题】:Adding anchors to Markdown section results in incomplete HTML fragments in section titles in the rendered Markdown将锚点添加到 Markdown 部分会导致呈现的 Markdown 中的部分标题中的 HTML 片段不完整
【发布时间】:2019-12-13 08:36:26
【问题描述】:

当我尝试使用此代码时

# Table of contents
1. [Introduction](#introduction)
2. [Some paragraph](#paragraph1)
    1. [Sub paragraph](#subparagraph1)
3. [Another paragraph](#paragraph2)

## This is the introduction <a name="introduction"></a>
Some introduction text, formatted in heading 2 style

## Some paragraph <a name="paragraph1"></a>
The first paragraph text

### Sub paragraph <a name="subparagraph1"></a>
This is a sub paragraph, formatted in heading 3 style

## Another paragraph <a name="paragraph2"></a>
The second paragraph text

我得到这个作为输出。

Introduction
Some paragraph
Sub paragraph
Another paragraph
" class="reference-link">This is the introduction
Some introduction text, formatted in heading 2 style

" class="reference-link">Some paragraph
The first paragraph text

" class="reference-link">Sub paragraph
This is a sub paragraph, formatted in heading 3 style

我的问题是我可以摆脱class="reference-link"&gt; 位吗?

对于我的编辑器,我使用的是名为 ipadao 的在线编辑器 http://editor.md.ipandao.com/#introduction.

我不知道它只是编辑器,还是我的一段代码。因为我对markdown(.md)很陌生

【问题讨论】:

  • 请提供 Markdown 解析器生成的 HTML。您可能需要使用浏览器的“查看源代码”工具。然后编辑您的问题并将 HTML 包含在代码块中。

标签: html markdown


【解决方案1】:

&lt;a&gt; 标签移动到它们应该锚定到的标题之前的行,如下所示:

# Table of contents
1. [Introduction](#introduction)
2. [Some paragraph](#paragraph1)
    1. [Sub paragraph](#subparagraph1)
3. [Another paragraph](#paragraph2)

<a name="introduction"></a>
## This is the introduction 
Some introduction text, formatted in heading 2 style

<a name="paragraph1"></a>
## Some paragraph
The first paragraph text

<a name="subparagraph1"></a>
### Sub paragraph
This is a sub paragraph, formatted in heading 3 style

<a name="paragraph2"></a>
## Another paragraph
The second paragraph text

我在ipandao 上对此进行了测试,它摆脱了您所看到的类引用链接片段,并且锚链接也很好用。

【讨论】:

  • 感谢您的回复,这是我得到的最简单的答案!
【解决方案2】:

Markdown 编译器通常具有内置规则,可以自动将生成的 ID 或类名添加到标头中。你需要告诉你的编译器不要自动生成 ID 和类名,或者使用自动生成的。

【讨论】:

  • 谢谢!我会试着找到这个。
猜你喜欢
  • 2019-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多