javascript - 将来自 GitHub 的代码作为代码块包含在 GitBook 中

标签 javascript github gitbook

如何在 GitBook 中显示这样的原始代码?

https://raw.githubusercontent.com/luyongxu/SignalPlot/master/Code/1.016%20Asset%20Bubbles.R

我认为这与以下内容有关:
Reading code from GitHub as text (raw) in a web page
但是我不知道如何调用主文档中的JavaScript函数。

最佳答案

只需添加一个 book.json文件到您的 GitBook。将其粘贴到其中:

{
    "plugins": ["github-embed"]
}

现在只需在您的页面中放置类似的内容:
{% github_embed "https://github.com/v5analytics/gitbook-plugin-github-embed/blob/1cd16ac/index.js#L3-L8" %}{% endgithub_embed %}

就是这么简单!

Here's some documentation.

注意:我让它在本地工作(使用 gitbook installgitbook serve),但它在 GitBooks 上对我不起作用,所以我提交了一个问题 herehere .

(证明它在本地工作)
enter image description here

代表 gitbook-plugin-github-embed 为他们弃用的代码道歉!

关于javascript - 将来自 GitHub 的代码作为代码块包含在 GitBook 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43904375/

相关文章:

javascript - MP3/MP4 PHP 上传不起作用

javascript - 如何打印pdf.js文件?

github - 运行 GitHub 搜索 API 时缺少 PR

git - 我可以像检查 git 存储库一样检查 github wiki 吗?

css - 更改 Bookdown 的 TOC 样式,Gitbook 样式

php - "invisible"数据 HTML 标签

javascript - 范围包含值,但访问它时,它是未定义的

git - 像 GitHub 垃圾这样的 Web 界面是否会收集悬挂的远程 git 提交,如果没有,是否有可能获取它们?

scala - 如何使用类似于 mdbook 的可运行片段编写 Scala 文档?

bookdown - 如何激活 bookdown 的全书范围或页面本地搜索