Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub MarkDown: Are Macros and Variables possible?

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.

like image 807
phatmanace Avatar asked Jul 04 '14 19:07

phatmanace


People also ask

Can you have variables in Markdown?

The idea is pretty simple, Markdown has a concept of reference links or reference-style links that allows us to define a value to a reference variable and then refer to that value later in the same document.

What does GitHub use for Markdown?

GitHub uses its own Markdown processor; GitHub Pages uses jekyll-commonmark. This means your README.md file will look different on GitHub's website than on your GitHub Pages website.

Does HTML work in GitHub Markdown?

Wherever HTML is rendered on GitHub (gists, README files in repos, comments on issues and pull requests, ...) you can use any of the HTML elements that GitHub Flavored Markdown (GFM) provides syntactic sugar for.

How do I edit Markdown in GitHub?

You can edit the Readme.md file in GitHub itself. Click on Readme.md, you will find an edit button. You can preview your changes and even commit them from there. Since it is a text file, Notepad or Notepad++ (Windows), TextEdit (Mac) or any other text editor can be used to edit and modify it.


2 Answers

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
like image 147
Adi Avatar answered Oct 06 '22 11:10

Adi


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

like image 41
Jordan Biserkov Avatar answered Oct 06 '22 12:10

Jordan Biserkov