markdown-Github:如何在README.md中嵌入要点?
是否可以将gits嵌入驻留在github存储库中的README.md文件中?
就像是:
<code id="gist-3167145"></code>
Francisco Luz asked 2020-08-10T21:56:02Z
4个解决方案
23 votes
不,对不起,那是不可能的。 您必须在README.md中具有指向它的链接或复制其内容。
Github Flavored Markdown将向您显示可以放入README.md文件的内容。
17 votes
更新:我的答案适用于通过jekyll构建的github页面。 我在markdown中使用脚本标签,然后由jekyll处理。
由于markdown支持html,因此可以简单地使用<script src="https://gist.github.com/nisrulz/11c0d63428b108f10c83.js"></script>
标记嵌入要点。
只需复制github提供的要点的嵌入网址
..并将其粘贴到markdown文件中。
示例:复制以下内容并粘贴到markdown文件中。
<script src="https://gist.github.com/nisrulz/11c0d63428b108f10c83.js"></script>
..这就是你会得到的
4 votes
如果使用的是降价预处理程序(例如Gitdown),则可以执行以下操作:
/**
* Resolve Gist (https://gist.github.com/)
*
* @param {Object} config
* @param {String} config.id Gist ID.
* @param {String} config.fileName Gist file name. Default to gistfile1.txt.
*/
gitdown.registerHelper('gist', {
compile: function (config) {
config = config || {};
config.fileName = config.fileName || 'gistfile1.txt';
if (!config.id) {
throw new Error('Gist ID must be provided.');
}
return new Promise(function (resolve) {
var https = require('https');
https.get({
host: 'api.github.com',
path: '/gists/' + config.id,
headers: {
// User agent is required to communicate with Github API.
'user-agent': 'Gitdown – gist'
}
}, function(res) {
var body = '';
res.setEncoding('utf8');
res.on('data', function (d) {
body += d;
});
res.on('end', function () {
var gist = JSON.parse(body);
if (!gist.files) {
throw new Error('Gist ("' + config.id + '") not found.');
}
if (!gist.files[config.fileName]) {
throw new Error('File ("' + config.fileName + '") is not part of the gist ("' + config.id + '").');
}
resolve(gist.files['gistfile1.txt'].content);
});
});
});
}
});
然后在您的降价中,您将使用JSON钩子引用Gist,例如
{"gitdown": "gist", "id": "d3e4212c799252bac5fa"}
此功能应在不久的将来成为Gitdown的一部分(有一个未解决的问题,[https://github.com/gajus/gitdown/issues/7)。]
3 votes
这在2017年使用GitHub Pages和Jekyll主题时是可行的:
参见@benbalter的[https://gist.github.com/benbalter/5555251]
简单为:{% gist 123456789 %}