Question
I am wondering if there is a way to get the content of a file on a github repo with specified line number(s) through GitHub APIs. I know that it is possible to generate a permanent link to a code snippet from the github UI as follows
https://github.com/<org_name>/<repo_name>/blob/master/<path_to_file>#L{Start}-L{End}
However I cant seem to find a way to get the content of a file on a specific line number(s) through their Github APIs. I tried the Search API but couldnt find anything useful. Any help on that is greatly appreciated!
Use Case
I am creating a tutorials application and I would like to query lines of code to generate dynamic code snippets from a file hosted on github.
Related
I am trying to create a readme on github like the following https://github.com/fleejy/ckme136-capstone
I guess my question is how did this content creator create the links under the Documentation And Repository Organization heading in the Readme.md file as I would like to emulate this.
I did some searching for relative references examples but was not able to figure it out.
Any advice would be very much appreciated.
Thanks
It's very Simple, you have to make a URL in markdown referring to your folder/file.
For making a URL in markdown files you use a syntax like this [Text](exampleURL) here your Text is the text which will appear in the markdown file and the exampleURL is the URL you want to go to.
A Working Example Will Be Like this [Google](https://google.com).
If you want to refer to a particular file/folder inside your repository you don't need https:// all you need is to provide the path of the folder/file
for example in my repository i have a file named example.pdf inside a folder named PDFs so my markdown code will look like this [Example PDF](PDFs/example.pdf)
Markdown is pretty easy and you can learn markdown syntax with this CheatSheet.
I Have seen several posts regarding this feature to preview HTML file on GitHub. Some suggest prepending https://htmlpreview.github.io/ before the real URL and some suggestions to create GitHub pages that I don't want to do now because then I have to re-create most of the thing on .yml
But my confusion is why this link showing HTML preview but not mine when I prepend the same string on my repo's HTML page. Please let me know If any other way I can see the HTML preview on github
Working:
https://htmlpreview.github.io/?https://github.com/bartaz/impress.js/blob/master/index.html
Not Working:
https://htmlpreview.github.io/?https://github.com/sany2k8/setuptools/blob/master/How_to_Install_Spark_on_Ubuntu.html
Showing 404 Not Found
Error: Cannot load
https://raw.githubusercontent.com/sany2k8/setuptools/master/How_to_Create_Github_Pages.html:
404 Not Found
Check these steps:
-Your repository is public.
(Settings>General>Danger Zone>Change repository visibility>Make public)
-The size of the files are not very large.
-The Repository link is in HTTPS and not in SSH.
EDIT:
I found this question about the private repository and preview, if you want to take a look.
When your html file is excessively big then often github may fail to open the file. In such cases you can check the raw version of the HTML file.
I would like to find a way to use nested url links in markdown (or a simple code) to be able to:
have a reference file in GitHub (reference.md) containing all the links that I cite several times in several *.md files in my repository. This to be able to correct broken links in one place without having to crosscheck all my files. Is this possible?
ex:
reference.md file contains: [citat1]:url
files 1.md...2.md..n.md contain code meaning something like: [citat1](lookup and use the url given in reference.md)
so if I click on citat1 on the generated webpage from the different files 1...2 the link would be active and redirect me to the appropriate url.
Anyone can help or point in the right direction? thanks
I was just reading this elasticsearch link. I found edit option with every heading which was redirecting me to GitHub website. I know git provides wiki option with every account but that is hosted on GitHub only and supports limited features.
How can I make documentation like this that is linked to GitHub?
It looks like they're using AsciiDoc and just put the repository on Github.
The edit links don't appear to be a special feature of AsciiDoc. They're simple URLs of the form https://github.com/<owner>/<repo>/edit/5.x/<path>. Presumably someone regenerates the site after they accept a pull request.
This will work with most site generation tools, it doesn't appear to be anything specific to AsciiDoc.
I read:
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-getting-started.html
Then I want edit, it redirect to:
https://github.com/elastic/elasticsearch-net/edit/5.x/docs/client-concepts/high-level/getting-started.asciidoc
Link source code:
https://github.com/elastic/elasticsearch-net/blob/5.x/docs/client-concepts/high-level/getting-started.asciidoc
URL file:
elasticsearch-net/docs/client-concepts/high-level/getting-started.asciidoc
The different is URL parameter: edit and blob. How to create documentation linked with GitHub? So simple, use this convention when create static document file.
I maintain a Github repository with currently two ipython notebook files.
My repository is here:
https://github.com/tschm/MosekRegression
When I try to open those files with the nbviewer, e.g. using
nbviewer.ipython.org
and inserting
http://nbviewer.ipython.org/urls/github.com/tschm/MosekRegression/blob/master/Data.ipynb
i get the 400 Bad Request Error. The file is good as it works when I make it available as a Gist. First research seems to indicate that this is a permission problem? I bet I do something stupid here...
Many thanks
Thomas
Expanding on #chuwy's answer, here's a breakdown of steps. The trick is to head to your file's page on github and then click on the "Raw" button:
then copy the url (minus the protocol string "http://"), and prepend it with "http://nbviewer.ipython.org/urls/"
So for example, if I have my iPython notebook:
https://github.com/watsonix/prediction_for_fun_and_profit/blob/master/statsmodel_outliers.ipynb
and I want to see it in the nbviewer, I click on "Raw" to get the URL:
https://raw.githubusercontent.com/watsonix/prediction_for_fun_and_profit/master/statsmodel_outliers.ipynb
which I use to form the URL:
http://nbviewer.ipython.org/urls/raw.githubusercontent.com/watsonix/prediction_for_fun_and_profit/master/statsmodel_outliers.ipynb
voila!
Valid link is http://nbviewer.ipython.org/urls/raw.github.com/tschm/MosekRegression/master/Minimum%20Variance.ipynb
Your link points to the github's html page with your file. You should give the raw file instead.
It now appears that gist automatically renders iPython notebooks! I have been using nbviewer, but I just noticed that GitHub renders the ipynb file perfectly.