Markdown - code as link in GitHub readme - github

I wanted to create inline span of code that links to other page.
I want to use
`MongoCollection`
and
[MongoCollection](#http://php.net/manual/en/class.mongocollection.php)
together to make a link on a code element.
I tried
[`MongoCollection`](#http://php.net/manual/en/class.mongocollection.php)
and
`[MongoCollection](#http://php.net/manual/en/class.mongocollection.php)`
Both didn't work.
Is there any way to do that?

Could you explain a bit more about what you mean by inline span of code? This works in Github and links the MongoCollection link to the Mongo Collection php manual page.
[MongoCollection](http://php.net/manual/en/class.mongocollection.php)
Is that what you are looking for?

Related

Mermaid syntax error on trying render a diagram on Github .md file

I've followed this MermaId tutorial but when I try put into my .md file on Github an error is raised:
This works perfectely on Live editor.
Code:
```mermaid
sequenceDiagram
autonumber
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
```
Someone can help me find my error on try write it on Github
Currently, I struggle on a similar problem.
With GitHub, do you mean GitHub pages?
Could you find a solution to it?
Personally, I have a setup with Jekyll. Here is my question on how to setup mermaid correctly for jekyll.
Interestingly, I just posted your mermaid into my jekyll page and the result is:
If I put it into <div> tags with class mermaid. Setup I used was this.
And if I use the jekyll spaceship-plugin, ist renders to:
I guess, that this what it should like. Am I right?
Therefore, so far, for me mermaid works based on the spaceship plugin, but not by "natively" referencing the mermaid JavaScript. I do not know if spaceship will work with GitHub pages, however, definitely within GitHub pages (which is based on Jekyll), you may also add plugins. See documentation for further details.

How embed code snippet into conversation?

I can't figure out how embed code snippets into my conversation, like this:
From google I found some tutorials like:
Introducing Embedded Code Snippets / Embedded Code Snippets / Creating a Permanent Link to a Code Snippet (they are all github official help documents)
and I tried follow them, but instead of showing nice box it shows as:
Did I miss something - maybe I have to enable it somewhere or is it available only for github Pro and Staff versions ?
I found the answer:
Permanent link will render as a code snippet only in the repository it originated in.
In other repositories, the permalink code snippet will render as a URL.

Github Gist Ghost Injection, Single Snipplet

I have my blog made by 'Ghost', and I'm trying to inject Github Gist in my post using the javascript github provides.
However, I usually keep a lot code snipplets in a single gist.
https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b
Like the link above, this gist contains 2 code snipplets.
However, I want to post only 1 of the 2 snipplets.
By the Github guide, normally you inject your gist like
<script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js"></script>
However, by this method, both the 2 snipplets show on my blog.
I tried like,
However, this doesn't showed snipplets at all.
Anyone knows a solution for this?
How about this? You can use a query parameter of file= for the URL.
When you want to embed 2.cpp from the gist, you can use a following code.
<script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js?file=2.cpp"></script>
When you want to embed temp.cpp from the gist, you can use a following code.
<script src="https://gist.github.com/devlphj/6631dc284065a5e61752d3970d74303b.js?file=temp.cpp"></script>
If I misunderstand your question, I'm sorry.

How to quote code in a Mardkown GitHub Gist

In a markdown file in a Gist, how do you quote some lines of code that are in a GitHub project?
If I was writing a Gist to try and explain how something works, I might have a block of text, then quote some code. I don't want to cut and paste the code in, I just want to quote some lines of code in a GitHub project. I am sure I have seen this done, but can't find an explanation of how to do it.
For example:
This algorithm makes use of Dijkstra's topological sort algorithm:
100: Result myFancyPantsAlgorithm(Blah blah) {
101: youGetTheIdea();
102: }
It is not possible to embed GitHub code snippets from Repositories.
What you might have seen is having a gist embedded in a "normal" website which is possible because GitHub provides a script to embed gists.
The script tag is (un)fortunately not whitelisted to be used in GitHub Flavored Markdown, so it is not possible to embed a gist in markdown.
A way to get around this would be to set a gh-page up, where you are able to embed a Gist as this SO-question shows. But then you're still not referencing to any live codebase.
So the answer to your question is: this is not possible, wether by embedding code from a repository nor by taking a detour via using gists.

markdown link opening in new tab

Is there a way to open the below markdown link in new tab? I've got some result from markdown target=“_blank”, but in my case it's different have used <> symbol to projected the link.
http://google.com
Not used the usual format
(name)[linkname]
Used
<>
Inside this projected the link name. Is possible to open this link in new tab?
The kramdown syntax:
[link name](url_link){:target="_blank"}
can be parsed into HTML using the kramdown online editor:
https://kramdown.herokuapp.com/
Then you can paste the HTML syntax into your markdown document.
I used it because I already had quite a few kramdown references, and wanted to avoid retyping them in HTML.
Doing some quick research - Markdown by default does not support this. Some solutions include using plugins like Kramdown, but I think the best solution is just to use an HTML tag in your markdown file. (as pointed out in the comment above ^)
# Some markdown
*click below*
New Tab
...
As far as I could find, this is not possible on GitHub currently. See good answer on this from Plaul here. I hope they will fix it soon, as it seems searching for an answer that this is something a lot of people would like to see.
If you have access to JavaScript, you can run a simple script to handle this for you wherever your markdown is rendered:
const anchors = document.querySelectorAll('a');
anchors.forEach((a) => {
a.setAttribute('target', '__blank');
a.setAttribute('rel', 'noopener noreferrer');
});