node.js - Github API Markdown - anchor 链接

标签 node.js github-api

我正在使用 .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 似​​乎根本不起作用。 iduser-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/

相关文章:

github - 如何在私有(private)组织中使用 GitHub API 进行搜索

github - 对 github 操作工作流程进行独特的检查运行

javascript - 围绕 Bing 翻译和 Node.js 构建项目

node.js - 使用 Bookshelf 补丁为未引用的列设置默认值

node.js - hyperledger-fabric "Writing your first Application"query.js 步骤失败

node.js - hapi.js 版本 18.x 类型

github - 找不到 hub.topic 的存储库 - 范围问题?

javascript - 使用node.js和socket.io向客户端发送信息时的延迟

github - 从 GitHub 和 GitLab *使用评论字段*下载 ssh 公钥

git - 标签和发布有什么区别?