How to embed only certain lines from a gist?

蓝咒 提交于 2019-12-03 04:55:20
khanmizan

Gist API doesn't provide any such way to embed part of a gist. However you can do it yourself with javascript in your end. there is a good library you can use:

https://github.com/kashif-umair/gist-embed/

You can embed parts of a gist with this.

What you need is this:

http://gist-it.appspot.com/

# Embed the file robertkrimen/gist-it-example/example.js
<script src="http://gist-it.appspot.com/github/robertkrimen/gist-it-example/blob/master/example.js"></script>

# Embed without a footer
<script src="http://gist-it.appspot.com/github/robertkrimen/gist-it-example/blob/master/example.js?footer=0"></script>

# Show only the first and second line
<script src="http://gist-it.appspot.com/github/robertkrimen/gist-it-example/blob/master/example.js?slice=0:1"></script>

There is a way to do it without libraries

Copy the embed and append to the src attribute the following ?file=the-name-of-your-file


A real example

The gist is https://gist.github.com/dianjuar/8df3873cd9db49b7fcd86e74b57dd848

So, to show in an embed only the file called circleci-useful-env-variables-pr.sh, I must

<script src="https://gist.github.com/dianjuar/8df3873cd9db49b7fcd86e74b57dd848.js?file=circleci-useful-env-variables-pr.sh"></script>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!