如何实现类似 github 的代码“嵌入”和“原始”功能?
我真的很喜欢github代码盒上的功能,尤其是“embed”和“raw”功能。我很好奇如何实现这样的代码盒。(不是代码突出显示,只是“embed”和“raw”函数)
您是否见过任何插件或其他东西可以做到这一点?
谢谢。
I really love the function on the github's code box, especially the 'embed' and 'raw' function.I am curious about how to implement a code box like that.(Not the code highlight,just the 'embed' and 'raw' function)
Have you every seen any plugins or some other thing can make that?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
他们是这样做的:他们的服务器上有原始文件,因此当您单击原始文件时,它只会执行以下脚本
对于“嵌入”功能,他们所做的是再次拥有代码,并在服务器上,他们将代码转换为 html,并添加用于语法突出显示的类。在他们给您的脚本中,只需 document.write 输出样式表的链接,然后 document.write 输出 HTML。我查看了 ruby 代码的脚本,如下:
我删除了很多 HTML 以缩短代码,但这就是想法。
Here is how they do it: they have the raw file on their server, so when you click raw, it just executes the following script
For the 'embed' functionality, what they do is they have the code again, and on the server, they convert the code to html with classes added for syntax highlighting. In the script that they give you, the just document.write out the link to the stylesheet and then document.write out the HTML. I have taken a look at the script for the ruby code, here it is:
I deleted a lot of the HTML to shorten the code, but that's the idea.