GitHub MarkDown: Are Macros and Variables possible?

GithubGithub Flavored-Markdown

Github Problem Overview


I've been learning github markdown, I had a question about variables and macros.

is it possible to define a variable or macro to prevent repeated printing of a block of text?

The use case is that I have a table producing a big grid of hyperlinks - the links look like the below.

http://www.a-big-long-big-big-long-hyperlink/more-long-stuff?id=1234

it would be nice if I could do something like the below once:

$link=http://www.a-big-long-big-big-long-hyperlink/more-long-stuff?id

and then in each cell in the table, I can say something like

$link=1234

Some other cell

$link=2345

the idea being that:

  • The table (which has ~10 columns and ~10 rows) is a bit easier to see on a normal screen, at the moment with the prefix to the links being so long, it looks really ugly as the links wrap to the next line
  • If I want to change the root link, I can change it in one place (yes, I know I could do search and replace in an editor!)

Cheers.

Github Solutions


Solution 1 - Github

Below are a few ways to write Reference-Links

[I'm an inline-style link](https://www.somewebsite.com)

[I'm an inline-style link with title](https://www.somewebsite.com "somewebsite's Homepage")

[I'm a reference-style link][Arbitrary case-insensitive reference text]

[I'm a relative reference to a repository file](../blob/master/LICENSE)

[You can use numbers for reference-style link definitions][1]

Or leave it empty and use the [link text itself]

Some text to show that the reference links can follow later.

[arbitrary case-insensitive reference text]: https://www.somewebsite.org
[1]: http://somewebsite.org
[link text itself]: http://www.somewebsite.com

Solution 2 - Github

You can use a feature of Markdown called "Reference-style links".

[link text][id] or just [link text] if link-text is unique and consist only of letters, numbers, spaces and punctuation. They are not case sensitive.

then somewhere in the document you define what id is:

[id]: http://example.com/whatever

See https://github.com/biserkov/markdown-playground/blob/master/README.md and

https://raw.githubusercontent.com/biserkov/markdown-playground/master/README.md

Solution 3 - Github

GitHub Markdown (for .md files) has variables through capture:

{% capture nameOfVariableToCapture %}any markdown here...{% endcapture %}

{{ nameOfVariableToCapture }} -- that prints the content of the variable

or from {% assign variableName = "text etc." %}.

As a test, I created https://github.com/SeLite/SeLite.github.io/blob/master/MarkdownTest.md. You can see its content at http://selite.github.io/MarkdownTest (ignore the header and footer, that comes from a framework).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionphatmanaceView Question on Stackoverflow
Solution 1 - GithubAdiView Answer on Stackoverflow
Solution 2 - GithubJordan BiserkovView Answer on Stackoverflow
Solution 3 - GithubPeter KehlView Answer on Stackoverflow