您可以在GitHub上创建一个Gist并将其嵌入您的网页:嵌入Gists.
这是一个随机选择的要点的例子:tap.groovy.
是否可以嵌入来自GitHub的其他代码文件,例如使用这个随机选择的C#文件ICommand.cs而不是Gist?
yus*_*shi 14
您可以尝试https://emgithub.com,它完全符合您的要求。
要将示例文件嵌入到ICommand.cs您的问题中,您只需在地址栏中的“github.com”之前添加“em”,然后按 Enter。
更新(2020年4月1日):
我发现,文件ICommand.cs中的问题不再可用,所以我使用的文件https://github.com/pytorch/pytorch/blob/master/torch/nn/cpp.py代替.
打开链接https://github.com/pytorch/pytorch/blob/master/torch/nn/cpp.py,你可以在地址栏中的“github.com”前加上“em”,然后按回车。
使用默认设置,您将获得以下脚本标记:
<script src="https://emgithub.com/embed.js?target=https%3A%2F%2Fgithub.com%2Fpytorch%2Fpytorch%2Fblob%2Fmaster%2Ftorch%2Fnn%2Fcpp.py&style=github&showBorder=on&showLineNumbers=on&showFileMeta=on&showCopy=on"></script>Run Code Online (Sandbox Code Playgroud)
您还可以更改其突出显示样式,并且可以使用“行号”、“文件元数据”等选项。
与其他做类似工作的网站不同,EmGithub.com 是一个托管在 Github Pages 上的静态网站。获取目标文件和突出显示在您的浏览器上完成。
您可以使用https://gist-it.appspot.com/:
<script src="http://gist-it.appspot.com/https://github.com/dotnet/corefx/blob/master/src/System.ObjectModel/src/System/Windows/Input/ICommand.cs"></script>Run Code Online (Sandbox Code Playgroud)
有一种通过 URL 将一个网站的内容嵌入另一个网站的标准,称为oEmbed。不幸的是,GitHub 不是 oEmbed 提供商,即它的 URL 不支持 oEmbed。
我找到了一个代理服务Oembed Proxy for GitHub,它添加了对 GitHub 代码 URL 的 oEmbed 支持。您将 GitHub URL 作为参数传递给代理的 URL,并且可以将生成的 URL 粘贴到另一个网站中(假设该网站支持嵌入 oEmbed 链接)。
另一个障碍是并非每个网站都支持嵌入 oEmbed URL。根据代理的文档,概念是一个支持它们的网站。我做了一些研究,看起来应该可以向wordpress或jekyll添加 oEmbed 支持。
由于 oEmbed 的采用很少,这个答案提供了非常有限的解决方案。尽管如此,我认为还是值得传播这个消息。
人们可以将fetch文件嵌入到自己的网站上。
fetch("https://raw.githubusercontent.com/Ayanmullick/test/master/AutomationAcc/test1.ps1")
.then(response => response.text())
.then(data => document.getElementById('code').textContent = data)Run Code Online (Sandbox Code Playgroud)
<pre id="code"></pre>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5039 次 |
| 最近记录: |