我正在使用 .md
文件为文档编写一个 NodeJS 应用程序,我正在使用这个:https://www.npmjs.com/package/github使用这个:https://developer.github.com/v3/markdown/ .
我正在通过他们的 API 传递我们的 .md
文件以返回 HTML,然后我将其缓存以备将来使用。
我在使用 anchor 链接时遇到问题。
当我有这个:# Standard Parameters
,我得到这些结果:
1.
使用 markdown.render()
与 mode: 'markdown'
和 markdown.renderRaw()
与 mode: 'markdown'
或 mode: 'gfm'
:
<h2><a id="user-content-standard-parameters" class="anchor" href="#standard-parameters" aria-hidden="true"><span class="octicon octicon-link"></span></a>Standard Parameters</h2>
2。
使用 markdown.render()
和 mode: 'gfm'
:
<h2>Standard Parameters</h2>
所以数字 1 生成了一个 anchor ,而数字 2 则没有。
但是,数字 1 似乎根本不起作用。 id
是 user-content-standard-parameters
(没有 name
属性),href
是 #标准参数
。
id
值不应该与 href
值匹配吗?像这样:
id="standard-parameters" href="#standard-parameters"
或
id="user-content-standard-parameters" href="#user-content-standard-parameters"
甚至
name="standard-parameters" href="#standard-parameters"
我错过了什么......?
最佳答案
看起来 Github 在他们自己的网站上使用了一些 JavaScript 来处理这个问题,所以我添加了一些我自己的东西来添加 name
属性,删除 user-content-
来自 id
值的位。
$(document).ready(function(){
$('a[id^="user-content-"]').each(function(i, a){
$(this).prop('name', a.id.replace('user-content-', ''));
});
});
关于node.js - Github API Markdown - anchor 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34814577/