I have a gist setup here. I use the following code to embed a single file from my gist to a webpage.
<script src="https://gist.github.com/4672365.js?file=1.java" type="text/javascript"></script>
But what I want is to embed a single line from file 1.java
. You can say that I want to embed only line #2 from file 1.java
into my webpage. Thanks in advance for help :)
It's quite simple.Input the code and click on 'create secret gist' – this way search engines wouldn't index your code and only people with the URL will have access to it. Share using the 'Embed' code option – copy the embed code and paste it within your WordPress code editor (the Text tab, not the Visual tab).
After I got no helpful answers to this question, I tried myself to do some javascript coding. I have uploaded that code on github. The file on this link does the magic. To embed a single line into your webpage you need to add reference to my javascript file in HEAD
tag. Here is a simple code.
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
<script type="text/javascript" src="https://github.com/kashif-umair/gist-embed/raw/feature/show_single_line/gist-embed.js" ></script>
</head>
<body>
<code id="gist-<YOUR_GIST_ID>" data-file="<YOUR_FILE_NAME_IN_GIST>" data-line="<LINE_NUMBER>"></code>
</body>
</html>
You need to replace YOUR_GIST_ID
with the ID of your gist, YOUR_FILE_NAME_IN_GIST
with the file name from which you want to embed the line and LINE_NUMBER
with the line number in file which you want to embed.
NOTE:
data-line="1-4,10,12-15"
. Please make sure that you used the correct syntax to put these values to avoid getting odd results.Hopefully I've helped for the people who have or will face this problem.
As I am continuously making changes to my javascript file so I think updating this answer every time is not a good idea at all. So from now I'll update the README.md file in the GitHub repository. Anyone having problems can visit the github to read README.md file. For reference I'm adding the link to my repository here.
https://github.com/kashif-umair/gist-embed
P.S: Please take a look at my javascript file in the github repository and suggest any good practices for coding.
The Right and fastest way to do is just append the .js address with ?file=file.name
: )
<script src="https://gist.github.com/kashif-umair/4672365.js?file=MyApplication.java"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With