Markdown 中的交叉引用(命名锚点) [英] Cross-reference (named anchor) in markdown

查看:57
本文介绍了Markdown 中的交叉引用(命名锚点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有 ma​​rkdown 语法相当于:

Is there markdown syntax for the equivalent of:

Take me to <a href="#pookie">pookie</a>

... 

<a name="pookie">this is pookie</a>

推荐答案

Take me to [pookie](#pookie)

应该是跳转到名为 pookie 的锚点的正确降价语法.

should be the correct markdown syntax to jump to the anchor point named pookie.

要插入该名称的锚点,请使用 HTML:

To insert an anchor point of that name use HTML:

<a name="pookie"></a>

Markdown 似乎并不介意你把锚点放在哪里.一个有用的地方是放在标题中.例如:

Markdown doesn't seem to mind where you put the anchor point. A useful place to put it is in a header. For example:

### <a name="tith"></a>This is the Heading

效果很好.(我会在这里演示,但 SO 的渲染器去掉了锚点.)

works very well. (I'd demonstrate here but SO's renderer strips out the anchor.)

这篇文章的早期版本建议使用 <a id='tith'/>,使用 XHTML 的自闭合语法,并使用 id属性而不是 name.

An earlier version of this post suggested using <a id='tith' />, using the self-closing syntax for XHTML, and using the id attribute instead of name.

XHTML 允许任何标记为空"和自关闭".也就是说, 的简写,一对匹配的带有空体的标签.大多数浏览器将接受 XHTML,但有些不接受.为避免跨浏览器问题,请按照上面的建议使用 明确关闭标记.

XHTML allows for any tag to be 'empty' and 'self-closed'. That is, <tag /> is short-hand for <tag></tag>, a matched pair of tags with an empty body. Most browsers will accept XHTML, but some do not. To avoid cross-browser problems, close the tag explicitly using <tag></tag>, as recommended above.

最后,属性name=在XHTML中被弃用了,所以我最初使用了大家都认可的id=.但是,HTML5 现在在使用 id= 时会在 JavaScript 中创建一个全局变量,这可能不一定是您想要的.因此,现在使用 name= 可能更友好.

Finally, the attribute name= was deprecated in XHTML, so I originally used id=, which everyone recognises. However, HTML5 now creates a global variable in JavaScript when using id=, and this may not necessarily be what you want. So, using name= is now likely to be more friendly.

(感谢 Slipp Douglas 向我解释 XHTML,以及 nailer 用于指出 HTML5 副作用 - 请参阅评论和 naileranswer 了解更多详情.name= 似乎适用于任何地方,但它在 XHTML 中已被弃用.)

(Thanks to Slipp Douglas for explaining XHTML to me, and nailer for pointing out the HTML5 side-effect — see the comments and nailer's answer for more detail. name= appears to work everywhere, though it is deprecated in XHTML.)

这篇关于Markdown 中的交叉引用(命名锚点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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