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.

 

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

$link= 

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.

5 Answers

Below are a few ways to write Reference-Links

[I'm an inline-style link]() [I'm an inline-style link with title]( "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]: [1]: [link text itself]: 
3

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]:

See and

1

This is not possible in basic Markdown, but there are extensions that add macros and variables. (Example.)

You can use brackets to do so if you're working with only markdown syntax and not html

First, you create the variables:

[foo]: [bar]: 

And then access the variables using the name in brackets:

I am the first [variable][foo] 

It even works on StackOverflow.

I am the second variable

1

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 . You can see its content at (ignore the header and footer, that comes from a framework).

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.