GitHub MarkDown: Are Macros and Variables possible? - github

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.

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

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

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).

Related

How to give name to quotation blocks in emacs org-mode

I have created a quote with the following syntax
#+BEGIN_QUOTE
My quote....
#+END_QUOTE
The problem is that in the collapsed view (when only titles and top-level outlines are shown), I see
#+BEGIN_QUOTE...
Which does not properly inform of the content of the quote. Is there a way to give a name or label to the quote so that I can see something like the below instead:
Quote from Jack...
Thank you
You can give names to blocks, whether those blocks are quote blocks, source blocks or any other kind (you can also give names to tables). The advantage is that each quote block can have its own name (in contrast to tags, which apply to a headline, so if you have more than one block in a section, the tag will not disambiguate them). On the other hand, names are more intrusive and to some extent defeat the purpose of collapsing: they are always there whether the block is collapsed or not; tags are more discreet:
* foo :quotes:
#+name: kennedy
#+begin_quote
Do not ask what your country can do for you...
#+end_quote
#+name: lincoln
#+begin_quote
Four score and seven years ago...
#+end_quote
Which one you want to use is up to you (and "both" is also a possibility).
Use tags
From the org manual:
An excellent way to implement labels and contexts for cross-correlating information is to assign tags to headlines

GitHub satanically messing with Markdown - changes 666 to DCLXVI

My GitHub repository has nothing but a readme in it. In this readme, locally I wrote this:
Factoids:
- There are about six different ways to do everything in Forked.
- There are actually six different ways to enter loops.
- There are six directionals and six I/O commands.
- 666. ha.
Emphasis on the last line.
What GitHub decided to show was not 666.
DCLXVI is the Roman Numeral number for 666.
This really creeped me out. My local file and the raw file both show 666.
What is GitHub doing, and why is the indentation on the un-numbered list messed up? Is this an easter egg, or some satanic bug?
This seems to be followed by github/markup issue 991, where on ordered sub-list, decimal numerals automatically turns into roman numerals.
I have found the cause of problem. It is CSS
This is the expected way for nested ordered lists to render in HTML.
This is not expected in HTML. https://jsfiddle.net/tf5jtv8s
We don't make any modifications to the default HTML behavior.
ol ol,ul ol{list-style-type:lower-roman}
I don't know CSS but my understanding is that this is the cause of problem. I can get expected result by disabling CSS. (I am from my mobile so I can't use browser inspector)
As mentioned in "A formal spec for GitHub Flavored Markdown", GitHub markdown spec GFM: GitHub Flavored Markdown Spec is built on top of the CommonMark Spec.
And as Tommi Kaikkonen mentioned in his answer, the ordered list is because of the dot following 666. See GFM Spec section 5.2.
As mentioned in section 6.1, any ASCII punctuation character may be backslash-escaped, to avoid this issue.
That means:
- 666\. ha.
(as explicitly shown in ForNeVeR's answer)
That is why that 666 number is changed to roman numerals in a GitHub README markdown.
Mike Lippert commented:
the 1st element in that list so it should show as i not dclxvi.
Markdown ordered lists ignore the actual number used and number sequentially, and I haven't seen a way to change that.
However, no: it shows dclxvi, because the generated html code is <ol start="666">, which is consistent with the GFM specs:
If the list item is ordered, then it is also assigned a start number, based on the ordered list marker"
(here, '666' is the ordered list marker)
Mike adds:
#VonC For anyone else here's another useful excerpt from VonC's doc link:
"The start number of an ordered list is determined by the list number of its initial list item. The numbers of subsequent list items are disregarded."
Also, why is the spacing messed up? I didn't catch that in your answer
You get an ordered list <ol> within an un-ordered list item <li>:
<ul>
<li>
<ol start="666">
<li>ha.</li>
</ol>
</li>
</ul>
GitHub CSS rules include:
.markdown-body ol {
padding-left: 2em;
}
If you put 3em, you would get
instead of
Adding a period after 666 makes it an ordered list marker.
GitHub declares CSS that renders ordered list markers using roman numerals:
ol ol,ul ol {
list-style-type: lower-roman
}
Escape the period with a backslash, and you should see the correct output.
While other answers are good at explaining why you have the problem, they haven't given you an exact example of how to fix that.
And it seems that you've already solved it in an imperfect manner, replacing your text with
- `666`. ha.
There's a common trick to escape the dot after the number to make it look like a normal text (and not an ordered list label):
- 666\. ha. (this will render as you probably want)

strikethrough code in markdown on github

I am talking about github markdown here, for files like README.md.
Question:
Is it possible to strikethrough a complete code block in markdown on github?
I know how to mark text as a block of code
this is
multiline code
and
this
this
also
by indenting by 4 spaces or by using ``` or `...
I also know how to strike through texts using
del tag
s tag
~~
Temporary solution:
Independently they work fine, but together not as expected or desired. I tried several combinations of the above mentioned.
For now, I use this:
striked
through
by using ~~ and ` for every single line.
Requirement:
I would like to have a code formatted text striked through, where the code block is continuous:
unfortunately, this is
not striked through
or at least with only a small paragraph in between:
unfortunately, also not
striked through
Is this possible at all?
I found some old posts and hints on using jekyll, but what I was searching for is a simple way, preferably in markdown.
This would only be possible with raw HTML, which GitHub doesn't allow. But you may be able to use a diff instead.
Code blocks are for "pre-formatted" text only. The only formatting you can get in a code block is the formatting that can be represented in plain text (indentation, capitalization, etc). There is no mechanism to mark up the content of a code block (as bold, italic, stricken, underlined, etc). This was an intentional design decision. Otherwise, how would you be able to show Markdown text in a code block? If you want formatted text, then you need to use something other than a code block.
As the rules state:
HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.
For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.
Therefore you would need to format your own custom HTML code block with the various bits marked up properly:
<pre><code><del>some stricken code</del>
<del>A second line of stricken code</del>
</code></pre>
However, for security reasons, GitHub will strip out any such raw HTML in your Markdown. So while this works where you have full control of the entire stack, on a hosted service it is most likely not possible.
However, I'm assuming you want to show some changes made to a block of code. As it turns out, a specific format already exists for that, namely, a diff. Just use a fenced code block with diff as the language and GitHub will format it correctly:
```diff
Unchanged Line
- Removed Line
+ Added Line
```
You can see how GitHub displays the above code block live (you can also see that in raw), but I've included a screenshot below for convenience.
I realize that the formatting does not use strike-through, but it does use a commonly used and understood format. For more complex blocks, you should probably use the diff utility program to generate the diff for you.
Expanding on Waylan's answer:
This may be obvious to others, but it caught me. When you have indented lines, be sure + or - is the first character on the line or it won't highlight.
```diff
<div>
Unchanged Line
<ul>
- <li>This won't work</li>
- <li>This will</li>
+ <li>1st character, then indent</li>
</ul>
</div>
```
After much much trying, I finally got it to work! It boils down to this:
inside ``` block, nothing is rendered (other than syntax highlights for language specified)
inside <code> block, markdown won't render, only HTML. You can use <strike>. It's fine, but you don't get the syntax coloring
now for the magic: use HTML for striking, and markdown for coloring:
<strike>
```language
this is
multiline code
```
</strike>
P.S. ``` blocks should always be surrounded by blank lines to work
On the subject of marking up the content of a code block, to tack an italicized string on to the end of a line of "code", try something like:
<code>id\_pn\_aside\_subscriber\_form\__form\_id_</code>
(You can see this in action at: https://github.com/devonostendorf/post-notif#how-do-you-use-the-stylesheet_filename-attribute-with-the-shortcode)
I had a hard time finding an example that matched this precise use case, so I hope this proves useful for anyone else trying to accomplish a similar effect.

Superscript within code block in Github Markdown

The <sup></sup> tag is used for superscripts. Creating a code block is done with backticks. The issue I have is when I try to create a superscript within a code block, it prints out the <sup></sup> tag instead of formatting the text between the tag.
How do I have superscript text formatted correctly when it's between backticks?
Post solution edit
Desired output:
A2 instead of A<sup>2</sup>
This is not possible unless you use raw HTML.
The rules specifically state:
With a code span, ampersands and angle brackets are encoded as HTML entities automatically, which makes it easy to include example HTML tags.
In other words, it is not possible to use HTML to format text in a code span. In fact, a code span is plain, unformatted text. Having any of that text appear as a superscript would mean it is not plain, unformatted text. Thus, this is not possible by design.
However, the rules also state:
Markdown is not a replacement for HTML, or even close to it. Its
syntax is very small, corresponding only to a very small subset of
HTML tags. The idea is not to create a syntax that makes it easier
to insert HTML tags. In my opinion, HTML tags are already easy to
insert. The idea for Markdown is to make it easy to read, write, and
edit prose. HTML is a publishing format; Markdown is a writing
format. Thus, Markdown's formatting syntax only addresses issues that
can be conveyed in plain text.
For any markup that is not covered by Markdown's syntax, you simply
use HTML itself. ...
So, if you really need some text in a code span to be in superscript, then use raw HTML for the entire span (be sure to escape things manually as required):
<code>A code span with <sup>superscript</sup> text and escaped characters: "<&>".</code>
Which renders as:
A code span with superscript text and escaped characters: "<&>".
This is expected behaviour:
Markdown wraps a code block in both <pre> and <code> tags.
You can use Unicode superscript and subscript characters within code blocks:
class SomeClass¹ {
}
Inputting these characters will depend on your operating system and configuration. I like to use compose key sequences on my Linux machines. As a last resort you should be able to copy and paste them from something like the Wikipedia page mentioned above.
¹Some interesting footnote, e.g. referencing MDN on <pre> and <code> tags.
If you're luck, the characters you want to superscript (or subscript) may have dedicated codepoints in Unicode. These will work inside codeblocks, as demonstrated in your question, where you include A² in backticks. Eg:
Water (chemical formula H₂O) is transparent, tasteless and odourless.
I've listed out the super and subscript Unicode characters in this Gist. You should be able to copy and paste any you need from there.

Only display one paragraph of text

You can set what the Facebook Share preview says. I would like it to be the first paragraph of my movable type entry. The people who make entries sometimes use
<p>
tags or they use the rich editor which puts in two
<br /><br />
tags to separate paragraphs.
Is there a way I can have movable type detect when the first paragraph end and only display the first paragraph? I would like to add that to my entry template so it will add some information to my head.
EntryBody has a lot of attributes to help format the output of the tag. You can use those to change the content so it shows up correctly in HTML, JavaScript, PHP, XML or other forms of output.
If you understand how to use regular expressions, you can use that and an additional language, say PHP, to break the body up into an array and only output the first paragraph or element of the array.
The simplest thing, though, I would think, would be to do something like
<mt:EntryBody words=100>
That will cut off the entry body after the first 100 words. You could also require users to upload an excerpt with the entry and use the entry excerpt for Facebook, instead.