After I did not get useful answers to this question, I tried to make some javascript codes. I downloaded this code on github . The file at this link does the magic. To insert one line in your web page, you need to add a link to my javascript file in the 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 identifier of your gist, YOUR_FILE_NAME_IN_GIST name of the file from which you want to insert the line and LINE_NUMBER , with the line number in the file that you want to embed.
NOTE :
- If you want to insert one line, then the code tag must contain both the file name and the line number.
- If you want to insert multiple sample lines from a file, then you should put values โโsimilar to the ranges of MS Word pages for printing. e.g.
data-line="1-4,10,12-15" . Please make sure you use the correct syntax so that these values โโavoid getting odd results. - If you want to insert the entire file, then remove the data-line attribute from the code tag.
I hope I helped people who have encountered this problem or have encountered it.
Since I am constantly making changes to my javascript file, so I think updating this answer every time is not a good idea. So now I am updating the README.md file in the GitHub repository. Anyone with a problem can visit github to read the README.md file. For reference, I am adding a link to my repository here.
https://github.com/kashif-umair/gist-embed
PS: Please see my javascript file in the github repository and suggest any useful methods for coding.
source share