Link to specific line in javascript source? - github

I have javascript source code served at http://www.example.com/static/script.js. I'm writing documentation and rather than including the code of certain functions I want to refer to, I'd just like to link to the source- but I would like to link to the specific line of the Function in the source document.
Is this possible, to create a link to a text document at a specific line without using html anchors or javascript window.scrollTo?

Never found a way to link to javascript source, but easy to do with GitHub - Just add "#L" + lineNo to the url. For instance: https://github.com/ArbolEric/RaphaGraph/blob/master/src.js#L210
Highlights and jumps to line.

Related

How does GitHub's Gist embed work?

Let's suppose that I have a file named my_python_code.py, and I upload it to GitHub's gist. Now I embed that gist into my blog, using the code provided by GitHub on the corresponding page.
When I browse my blog and I check the source code for the page, I discover that:
the embed code calls a js file which performs some DocumentWrite commands, inserting the appropriate html tags (with css styles) on my page, and
the associated css file is linked to my page. This file contains css declarations for 'gist' class as well as other classes.
This is all very nice. But I wonder: starting from the same my_python_code.py file, what would I have to do to end up with the same final html code?
I've tried using pygments and rouge (via pygmentize and rougify commands) with reasonable options but none of them highlights the original code using 'gist' tags (among others) as is done when performing the GitHub embed.

Get HTML Equivalent of Google Doc contents

I am trying to get the HTML for a Google Doc's contents. The methods I have found all seem to use deprecated items. I ultimately want to use the Doc as a template for an email. I have everything working except getting the HTML version of the text. Yes, I want the full HTML version including tables, images, and anything else I can place in the Doc.
Is there any way to get this?
Regards,
Karl S
I believe the following method works:
Open up the Google Doc you want to work with
Click File-->Publish to the web
Click Link and then Publish
Copy the link into another tab
View the source for the page and copy everything inside and including <div id="contents">
This should be the complete HTML for that document. I just verified that it works with a document of mine. Let me know if it doesn't.

How do I view the source of Markdown files on Github?

Github helpfully renders Markdown (.md) files to HTML when viewing on github.com (for example, this README.md).
When viewing any other source file, it is shown as unrendered source code (for example, this .gitignore). A handy feature this gives is linking directly to a line in the source by clicking the line number (for example, like this).
How can I view the unrendered source of Markdown files on Github (so I can link to a particular line in the source)?
note: I know of the "Raw" button, however it does not provide any of the nice UI Github has.
If you don't want to use the "raw" button, you can (since June 2021) add ?plain=1 to your GitHub markdown file URL:
Appending ?plain=1 to the url for any Markdown file will now display the file without rendering.
As with other code files, it will also show line numbers, and can be used to link other users to a specific line or lines.
For example, appending ?plain=1#L52 will highlight line 52 of a plain text Markdown file.
Example:
https://github.com/git/git/blob/master/README.md?plain=1#L49-L51
Since Sept. 2021, there is a button which adds the ?plain=1 for you:
Use the "Raw" button. For instance, if you were looking at README.md there is a Raw button in the Navigation. This can be simple URL change (from blob to raw), but in this case becomes a separate link.
Edit: There is no "pretty" view for the Markdown source. There's the converted HTML view, the Raw view without the UI, and the Blame view. Only the Blame view provides you with the ability to link to a specific line within the source.
Edit 2: The other option is to use Anchors within the README.md. If you take the Installation title for example, you can directly link within the content of the Markdown file. Assuming you don't have anything hidden within the Markdown itself, this is closer still to solving your original question.
Using the "Blame" button, you are able to see the source of the Markdown (for example, like this).
Unfortunately, "Blame" comes with extra UI elements which make the source more cluttered.
Refined Github provides an additional "Raw" button to view the raw source and link to a specific line:
I ran into this issue, as a complete surprise to me, on a file with a .wiki extension. It appears that files with .wiki, .mediawiki, and .wikitext extensions are recognized and rendered as HTML, with a table of contents even. I guess it makes sense, what with GitHub projects having wikis and all.
That's nifty, but this one particular case, I really wanted the raw wikitext to be visible and copy-pasteable, not some rendered representation of it.
The only half-way solution I found was to use a bogus file extension that isn't one of the ones recognized by GitHub, and then a .gitattributes to tell GitHub how to syntax highlight it, e.g.:
*.wiki_ linguist-language=mediawiki
I'm not thrilled about this, but all the good extensions were already "taken" according to the languages.yml linked above.

How do I embed a single file from a GitHub gist with the new gist interface?

The new GitHub Gist interface has one embed snippet for the entire gist which embeds all files in the gist. The old interface had embed code for each file in the gist. Anyone know if there's a trick to embed a single file?
Take the gist URL from the left-hand side and after the .js add a query string like ?file=myFile.blah, e.g.
<script src="https://gist.github.com/4505639.js?file=macroBuild.scala" type="text/javascript"></script>
Medium
For those who want to use it on the medium, Medium does not support and does not query parameters in the URL when you add it after the paste of the URL. So just follow these 4 steps IN THE ORDER.
So:
⚠️ Order matters!
Copy the (multi-file) gist path. e.g.:
https://gist.github.com/MojtabaHs/91e34fd0e987fe7ce801936dc6ece0e8
Paste it somewhere else than the Medium article that not preserves the rich data of the text. Like an online textbox for example:
⚠️ Do not hit search or return button
Append the query param for the file to the URL. e.g:
https://gist.github.com/MojtabaHs/91e34fd0e987fe7ce801936dc6ece0e8?file=Interface.swift
Note that ?file=Interface.swift at the end of the URL, right?
Copy and paste it in the article and see the magic 🔮
An article using this method:
Implement Custom Activity Indicator With The SwiftUI
The MOST Important note that MUST be considered:
⚠️ Note that you MUST copy an unformatted plain text in the medium and MUST NOT edit the URL after pasting it in the Medium! You can copy the link in an online textbox like google.com and after appending the query, copy it back and paste it in the Medium.
GitHub provides this same information here on their site. As others have said the official way is to attach ?file=name-of-file.ext to the end of the embed code's URL in order to only embed the file called name-of-file.ext (you can of course change the name to whatever the name of your file is). For example, if I wanted to embed the getGitContents.js file from the Gist at https://gist.github.com/westc/afac9258389fdfd2fdaf134ffaa0e923 I can use the following:
<script src="https://gist.github.com/westc/afac9258389fdfd2fdaf134ffaa0e923.js?file=getGitContents.js"></script>
In addition there is this YourJS blog post about this which allows you to enter your user name and see the embed codes for all of your gists and the underlying individual files.
Just for other people reference that might be looking into this.
If you are using Wordpress you may achieve this with the plugin oEmbed-gist and shortcode style:
[gist id="your-gist-id-here" file="your-file-name.js"].

change html output doxygen link

I am working on a project that is heavily documented with doxygen.
In a UI I have a list of all the classes available - I would like to be able to open the right documentation page of the class I select. In order to do that I need an easy to read link, so I can dynamically build it and run it.
Is it there any way I can control the generated link of the html file? Because the ones I have right now are impossible do be built dynamically.
You could use Doxygen's tag file mechanism for that (see GENERATE_TAGFILE in the config file).
A tag file is a reasonably easy to understand and parse XML file that basically lists all symbols in your project, with for each symbol the corresponding (relative) URL to the documentation.
So you could parse the tag file from your UI to resolve the links to the doxygen generated documentation in a robust way.