如何链接到 Multimarkdown 中的命名锚点?
我曾多次提到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
在标准 Markdown 中,将锚点
放置在要链接到的位置,并通过
[链接文本] 在同一页面上引用它](#abcd)
。这使用
name=
而不是id=
,原因请参见此答案< /a>.远程引用可以使用
[链接文本](http://...#abcd)
。只要您能够控制源文本和目标文本,这就像梦想一样。锚点甚至可以出现在标题中。示例:此 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 notid=
, 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 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.
如果 Markdown 文件中有标题,则可以直接在文件中链接它们。
Markdown 标题:
这将生成一个隐式 id
#the-header
(用连字符替换内部空格并小写)。要导航到此 ID,您可以创建如下链接:
这相当于:
请注意引用的名称是小写的
#header
。If you have headers in the markdown files, you can directly link them in the file.
Markdown 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:
This is equivalent to:
Please note the reference's name is a lower-case
#header
.摘自 Multimarkdown 用户指南(感谢 Twitter 上的 @MultiMarkdown 指出)
[Some Text][]
将链接到名为“Some Text”的标头例如,
您选择的可选标签可帮助消除多个标题具有相同标题的情况的歧义:
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.
An optional label of your choosing to help disambiguate cases where multiple headers have the same title:
我测试了 Github Flavored Markdown 一段时间,可以总结为四个规则:
-
例如,如果您的部分被命名为:
通过以下方式创建指向它的链接:
I tested Github Flavored Markdown for a while and can summarize with four rules:
-
For example, if your section is named this:
Create a link to it this way:
创建内部链接(与部分相关)的最佳方法是创建列表,但如果标题包含空格,则放置
#section
或#section-title
而不是链接。Markdown
列表预览
HTML
不管是
h1
、h2
,h3
等标头,您始终仅使用一个#
来引用它。部分列表中的所有引用都应转换为小写文本,如上例所示。
该部分的链接应为小写。否则将无法工作。该技术对于所有 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
List preview
HTML
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
在 mdcharm 中是这样的:
In mdcharm it is like this:
这是另一个选项,因此所有链接都可以放置在文件的底部:
Here is another option so all the links can be placed at the bottom of the file:
这是我的解决方案(源自
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.对我来说,使用 dataiku,我有一个像上面这样的标题:
如果我想跳到它上面,
我是如何找到“#pr-fixes-redshifts-1”的?
在查看模式下,将鼠标悬停在目的地上并等待工具提示
For me, with dataiku, I have a header like that :
above, if I want jump on it
How I've found "#pr-fixes-redshifts-1" ?
In view mode, the mouse over the destination and wait the tooltip
能够链接到锚点的一个重要部分是使用易于使用的
id
命名锚点。这是通过{#foo- bar}
标题上的(扩展)语法,受某些处理器支持(Kramdown、Maruku;显然不是 Github 或 SO)如何(示例){#how- to}
如图所示完成在此行末尾:
这允许任意命名标题(但保持 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:
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.