Markdown:如何通过编号引用编号列表中的项目(例如LaTeX的\ ref/\ label)? [英] Markdown: How to reference an item in a numbered list, by number (like LaTeX's \ref / \label)?

查看:230
本文介绍了Markdown:如何通过编号引用编号列表中的项目(例如LaTeX的\ ref/\ label)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在markdown中,有什么方法可以等效于此LaTeX代码段中的交叉引用吗? (摘自此处.)

Is there any way in markdown to do the equivalent of the cross-referencing in this LaTeX snippet? (Taken from here.)

\begin{enumerate}
    \item \label{itm:first} This is a numbered item
    \item Another numbered item \label{itm:second}
    \item \label{itm:third} Same as \ref{itm:first}
\end{enumerate}
Cross-referencing items \ref{itm:second} and \ref{itm:third}.

此LaTeX生成

1. This is a numbered item
2. This is another numbered item
3. Same as 1

Cross-referencing items 2 and 3.

也就是说,我希望能够在降价列表中引用项目而无需对其进行显式编号,以便无需手动更新交叉引用就可以将上述列表更改为以下内容:

That is, I would like to be able to refer to items in a markdown list without explicitly numbering them, so that I could change the above list to the following without having to manually update the cross references:

1. This is the very first item
2. This is a numbered item
3. This is another numbered item
4. Same as 2

Cross-referencing items 3 and 4.

推荐答案

HTML甚至无法做到这一点,而Markdown是HTML的子集,因此答案是否定的.

HTML can't even do that and Markdown is a subset of HTML, so the answer is no.

例如,您的列表将这样表示(由Markdown渲染时):

For example, your list would be represented like so (when rendered by Markdown):

<ol>
    <li>This is a numbered item</li>
    <li>This is another numbered item</li>
    <li>Same as 1</li>
</ol>

请注意,就编号而言,没有任何指示.所有这些都是在浏览器渲染时推断出来的.但是,数字值未存储在文档中,并且不可引用或不可链接.它们仅用于显示,没有其他目的.

Notice that there is no indication of which item is which as far as the numbering goes. That is all inferred at render time by the browser. However, the number values are not stored within the document and are not referancable or linkable. They are for display only and serve no other purpose.

现在,您可以编写一些自定义HTML来唯一地标识每个列表项并使它们可引用:

Now you could write some custom HTML to uniquely identify each list item and make them referencable:

<ol>
    <li id="item1">This is a numbered item</li>
    <li id="item2">This is another numbered item</li>
    <li id="item3">Same as <a href="#item1>1</a></li>
</ol>

但是,这些ID是硬编码的,与用于显示项目的数字无关.虽然,我想这就是您想要的.要进行更新的更改,请执行以下操作:

However, those IDs are hardcoded and have no relation to the numbers used to display the items. Although, I suppose that's what you want. To make your updated changes:

<ol>
    <li is="item0">This is the very first item</li>
    <li id="item1">This is a numbered item</li>
    <li id="item2">This is another numbered item</li>
    <li id="item3">Same as <a href="#item1>2</a></li>
</ol>

ID随项目保留在一起.但是,让我们转到这些列表项的链接.请注意,在第一次迭代中,我们有:

The IDs stay with the item as intended. However, lets move on to the links to those list items. Note that in the first iteration we had:

<a href="#item1>1</a>

有了更新,我们有了:

<a href="#item1>2</a>

唯一的区别是链接的标签(从"1"更改为"2").那实际上是通过某种宏魔术东西来更改文档文本. HTML不能做的事情,至少没有JavaScript和/或CSS不能帮助.

The only difference being the link's label (changed from "1" to "2"). That is actually changing the document text through some sort of macro magic stuff. Not something HTML can do, at least not without JavaScript and/or CSS to help.

换句话说,每次更新列表时,每次引用该项目的文本都需要在整个文档中进行手动更新.这是针对HTML的. Markdown呢?由于规则状态:

In other words, the text of every reference to the item would need to be manually updated throughout the document every time the list is updated. And that is for HTML. What about Markdown? As the rules state:

Markdown不能替代HTML,甚至不能替代HTML.它的语法非常小,仅对应一小部分HTML标签.

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags.

因此,在标准Markdown中,甚至没有任何方法可以将ID分配给列表项.

Therefore in standard Markdown there is not even any way to assign IDs to the list items.

在我看来,您要么需要使用列表以外的其他内容,要么需要Markdown/HTML以外的其他内容.

Seems to me you either need to use something other than lists or use something other than Markdown/HTML.

这篇关于Markdown:如何通过编号引用编号列表中的项目(例如LaTeX的\ ref/\ label)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆