如何链接到 Multimarkdown 中的命名锚点?

发布于 2024-11-19 19:46:13 字数 155 浏览 3 评论 0原文

我曾多次提到 MultiMarkdown 对内部链接/命名锚点的支持,但我无法找到如何实际执行此操作的单个示例。

那么,表示命名锚点的语法是什么,链接到它的语法是什么(与链接到任何其他 URL 相同)(仅使用 #foo 而不是 http://....)?

I have come across a number of mentions of MultiMarkdown's support for internal links / named anchors but I am unable to find a single example of how to actually do it.

So, what is the syntax for denoting the named anchor, and what is the syntax for linking to it the same as linking to any other URLs (only using #foo instead of http://....)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

可爱暴击 2024-11-26 19:46:13

在标准 Markdown 中,将锚点 放置在要链接到的位置,并通过 [链接文本] 在同一页面上引用它](#abcd)

这使用 name= 而不是 id=,原因请参见此答案< /a>.

远程引用可以使用[链接文本](http://...#abcd)。只要您能够控制源文本和目标文本,这就像梦想一样。锚点甚至可以出现在标题中。示例:

### <a name="head1234"></a>A Heading in this SO entry!
#### Best answer is in this [link](#head1234)

此 SO 条目中的标题!

最好的答案就在这个链接中。


注意:在 StackOverflow 上,这种类型的链接不起作用,因为锚点被剥离,因此我们必须使用带有片段的 URL 来模拟链接行为。

In standard Markdown, place an anchor <a name="abcd"></a> where you want to link to and refer to it on the same page by [link text](#abcd).

This uses name= and not id=, for reasons explained in this answer.

Remote references can use [link text](http://...#abcd). This works like a dream, provided you have control over the source and target texts. The anchor can even appear in a heading. Example:

### <a name="head1234"></a>A Heading in this SO entry!
#### Best answer is in this [link](#head1234)

A Heading in this SO entry!

The best answer is in this link.


Note: Here on StackOverflow, this type of link doesn't work because the anchor is stripped, so we have to use a URL with a fragment to mimic the link behavior.

峩卟喜欢 2024-11-26 19:46:13

如果 Markdown 文件中有标题,则可以直接在文件中链接它们。

Markdown 标题:

## The Header

这将生成一个隐式 id #the-header (用连字符替换内部空格并小写)。

要导航到此 ID,您可以创建如下链接:

[Link to Header](#the-header)

这相当于:

<a href="#the-header">Link to Header</a>

请注意引用的名称是小写的 #header

If you have headers in the markdown files, you can directly link them in the file.

Markdown Header:

## The Header

this will generate an implicit id #the-header (replace internal spaces with hyphens and make lowercase).

To navigate to this id, you can create the link like this:

[Link to Header](#the-header)

This is equivalent to:

<a href="#the-header">Link to Header</a>

Please note the reference's name is a lower-case #header.

╭⌒浅淡时光〆 2024-11-26 19:46:13

摘自 Multimarkdown 用户指南(感谢 Twitter 上的 @MultiMarkdown 指出)

[Some Text][]将链接到名为“Some Text”的标头
例如,

### Some Text ###

您选择的可选标签可帮助消除多个标题具有相同标题的情况的歧义:

### Overview [MultiMarkdownOverview] ##

这允许您使用 [MultiMarkdownOverview] 专门引用此部分,而不是另一个名为“概述”的部分。这适用于 atx 或 settext 样式的标头。

如果您已经使用标头使用的相同 ID 定义了锚点,则定义的锚点优先。

除了文档中的标题之外,您还可以提供图像和表格的标签,然后也可以将其用于交叉引用。

Taken from the Multimarkdown Users Guide (thanks to @MultiMarkdown on Twitter for pointing it out)

[Some Text][]will link to a header named “Some Text”
e.g.

### Some Text ###

An optional label of your choosing to help disambiguate cases where multiple headers have the same title:

### Overview [MultiMarkdownOverview] ##

This allows you to use [MultiMarkdownOverview] to refer to this section specifically, and not another section named Overview. This works with atx- or settext-style headers.

If you have already defined an anchor using the same id that is used by a header, then the defined anchor takes precedence.

In addition to headers within the document, you can provide labels for images and tables which can then be used for cross-references as well.

感受沵的脚步 2024-11-26 19:46:13

我测试了 Github Flavored Markdown 一段时间,可以总结为四个规则:

  1. 标点符号将被删除
  2. 前导空格将被删除
  3. 大写将被转换为小写
  4. 字母之间的空格将被转换为 -

例如,如果您的部分被命名为:

## 1.1 Hello World

通过以下方式创建指向它的链接:

[Link](#11-hello-world)

I tested Github Flavored Markdown for a while and can summarize with four rules:

  1. punctuation marks will be dropped
  2. leading white spaces will be dropped
  3. upper case will be converted to lower
  4. spaces between letters will be converted to -

For example, if your section is named this:

## 1.1 Hello World

Create a link to it this way:

[Link](#11-hello-world)
流云如水 2024-11-26 19:46:13

创建内部链接(与部分相关)的最佳方法是创建列表,但如果标题包含空格,则放置 #section#section-title 而不是链接。

Markdown

Go to section
* [Hello](#hello)  
* [Hello World](#hello-world)
* [Another section](#new-section) <-- it's called 'Another section' in this list but refers to 'New section'


## Hello
### Hello World
## New section

列表预览

Go to section
Hello           <-- [Hello](#hello)                 -- go to `Hello` section
Hello World     <-- [Hello World](#hello world)     -- go to `Hello World` section
Another section <-- [Another section](#new-section) -- go to `New section`

HTML

<p>Go to section</p>
<ul>
    <li><a href="#hello">Hello</a></li>
    <li><a href="#hello-world">Hello World</a></li>
    <li><a href="#new-section">Another section</a> <– it’s called ‘Another section’ in this list but refers to ‘New section’</li>
</ul>
<h2 id="hello">Hello</h2>
<h3 id="hello-world">Hello World</h3>
<h2 id="new-section">New section</h2>

不管是h1h2h3 等标头,您始终仅使用一个 # 来引用它。
部分列表中的所有引用都应转换为小写文本,如上例所示。

该部分的链接应为小写。否则将无法工作。该技术对于所有 Markdown 变体以及 MultiMarkdown 都非常有效。

目前我正在使用 Pandoc 来转换文档格式。它比 MultiMarkdown 好得多。
在此处测试 Pandoc

The best way to create internal links (related with sections) is create list but instead of link, put #section or #section-title if the header includes spaces.

Markdown

Go to section
* [Hello](#hello)  
* [Hello World](#hello-world)
* [Another section](#new-section) <-- it's called 'Another section' in this list but refers to 'New section'


## Hello
### Hello World
## New section

List preview

Go to section
Hello           <-- [Hello](#hello)                 -- go to `Hello` section
Hello World     <-- [Hello World](#hello world)     -- go to `Hello World` section
Another section <-- [Another section](#new-section) -- go to `New section`

HTML

<p>Go to section</p>
<ul>
    <li><a href="#hello">Hello</a></li>
    <li><a href="#hello-world">Hello World</a></li>
    <li><a href="#new-section">Another section</a> <– it’s called ‘Another section’ in this list but refers to ‘New section’</li>
</ul>
<h2 id="hello">Hello</h2>
<h3 id="hello-world">Hello World</h3>
<h2 id="new-section">New section</h2>

It doesn't matter whether it's h1, h2, h3, etc. header, you always refer to it using just one #.
All references in section list should be converted to lowercase text as it is shown in the example above.

The link to the section should be lowercase. It won't work otherwise. This technique works very well for all Markdown variants, also MultiMarkdown.

Currently I'm using the Pandoc to convert documents format. It's much better than MultiMarkdown.
Test Pandoc here

南七夏 2024-11-26 19:46:13

在 mdcharm 中是这样的:

* [Descripción](#descripcion)
* [Funcionamiento](#funcionamiento)
* [Instalación](#instalacion)
* [Configuración](#configuracion)

### Descripción {#descripcion}
### Funcionamiento {#funcionamiento}
### Instalación {#instalacion}
### Configuración {#configuracion}

In mdcharm it is like this:

* [Descripción](#descripcion)
* [Funcionamiento](#funcionamiento)
* [Instalación](#instalacion)
* [Configuración](#configuracion)

### Descripción {#descripcion}
### Funcionamiento {#funcionamiento}
### Instalación {#instalacion}
### Configuración {#configuracion}
但可醉心 2024-11-26 19:46:13

这是另一个选项,因此所有链接都可以放置在文件的底部:

Here is an [example label].

  [example label]: #the-anchor-name-or-id "Optional title for mouse hover"

Here is another option so all the links can be placed at the bottom of the file:

Here is an [example label].

  [example label]: #the-anchor-name-or-id "Optional title for mouse hover"
眼眸 2024-11-26 19:46:13

这是我的解决方案(源自 SaraubhM 的答案)

**跳转到**:[热键和标记](#hotkeys-markers) / [半径](#radii) / [路线向导 2.0](#route-wizard-2-0)

它为您提供:

跳转到:热键和标记/半径/路线向导 2.0

请注意从 .- 的更改,以及 & 的丢失> 在链接中。

Here is my solution (derived from SaraubhM's answer)

**Jump To**: [Hotkeys & Markers](#hotkeys-markers) / [Radii](#radii) / [Route Wizard 2.0](#route-wizard-2-0)

Which gives you:

Jump To: Hotkeys & Markers / Radii / Route Wizard 2.0

Note the changes from and . to - and also the loss of the & in the links.

谈情不如逗狗 2024-11-26 19:46:13

对我来说,使用 dataiku,我有一个像上面这样的标题:

### Préfixes Redshifts

如果我想跳到它上面,

 [Préfixes Redshifts](#pr-fixes-redshifts-1)

我是如何找到“#pr-fixes-redshifts-1”的?
在查看模式下,将鼠标悬停在目的地上并等待工具提示

For me, with dataiku, I have a header like that :

### Préfixes Redshifts

above, if I want jump on it

 [Préfixes Redshifts](#pr-fixes-redshifts-1)

How I've found "#pr-fixes-redshifts-1" ?
In view mode, the mouse over the destination and wait the tooltip

蘸点软妹酱 2024-11-26 19:46:13

能够链接到锚点的一个重要部分是使用易于使用的id命名锚点。这是通过{#foo- bar} 标题上的(扩展)语法,受某些处理器支持(Kramdown、Maruku;显然不是 Github 或 SO)

如何(示例){#how- to}

如图所示完成在此行末尾:

### Typical Long Heading (w/ needing _annoying_ "escaping") {#some-heading}

这允许任意命名标题(但保持 ID 简单!),并且避免必须仔细制作它们以避免任何转义字符。它还可以让您更好地控制文档。 (请注意,TOC 生成器可能不尊重这些。)

现在引用始终可以使用简单的[重要地点](#some-heading)语法,内部;并在外部使用[可能是其他名称](http://example.com/some-page#some-heading)

这里(链接甚至没有显示)是一个 SO 处理器示例,展示了它如何在这里不起作用。

An important piece of being able to link to an anchor is naming the anchor with an easy-to-use id. This is done with the {#foo-bar} (extended) syntax on the heading, supported by some processors (Kramdown, Maruku; not Github or SO apparently)

How To (an example) {#how-to}

It's done as shown at the end of this line:

### Typical Long Heading (w/ needing _annoying_ "escaping") {#some-heading}

This allows for arbitrarily named headings (but keep the IDs simple!), and avoids having to carefully craft them to avoid any escaped characters. It also gives you better control of your document. (Be warned that TOC-generators may not respect these, though.)

Now the references can always be made with the simple [Important Place](#some-heading) syntax, internally; and with [Some other name maybe](http://example.com/some-page#some-heading), externally.

Here (link not even showing up) is a SO processor example showing how it sadly doesn't work here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文