【发布时间】:2011-06-12 02:36:00
【问题描述】:
我有一些包含 GitHub Gists 的 URL 的文本。我想查找这些 URL 并将 Gist 内联放在内容客户端。我尝试过的一些事情:
直接查找 GitHub 的 OEmbed API。
对于https://gist.github.com/733951,这意味着我执行 JSON-P 查找
https://github.com/api/oembed?format=json&url=https%3A%2F%2Fgist.github.com%2F733951,
提取对象的html 属性,并将其添加到我的页面。问题
这里是 GitHub 的 OEmbed API 只返回 Gist 的前三行。
使用jQuery-embedly plugin。
打电话
jQuery('a.something').embedly({allowscripts: true})
有效,但 Embedly 从 Gist 中剥离了格式。将其包装在 <pre> 标记中并没有帮助,因为没有换行符。
使用 GitHub 的 .js 版本的 gist。
https://gist.github.com/733951.js 使用document.write,所以当我动态需要它时,我无法控制页面的位置。 (如果我可以将它写入 HTML 源代码,它会显示在正确的位置,但这一切都是在客户端完成的。)
【问题讨论】:
标签: javascript jquery github oembed