Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>

like image 728
Aaron Avatar asked Jul 18 '16 01:07

Aaron


People also ask

How do I superscript in Github Markdown?

Use the <sup></sup> tag ( <sub></sub> is the equivalent for subscripts).

How do you add a superscript in Markdown?

To create a superscript, use one caret symbol ( ^ ) before and after the characters. Alternatively, if your Markdown application supports HTML, you can use the sup HTML tag.

How do you write subscript and superscript in Markdown?

To indicate a subscript, use the underscore _ character. To indicate a superscript, use a single caret character ^ . Note: this can be confusing, because the R Markdown language delimits superscripts with two carets.

Does Markdown support superscript?

superscript and subscript in HTML are used to display text content with typographical styles. It provides Superscript (sup) and subscript (sub) tags in html. Markdown does not support superscript and subscript natively.


2 Answers

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: "&lt;&amp;&gt;".</code>

Which renders as:

A code span with superscript text and escaped characters: "<&>".

like image 119
Waylan Avatar answered Sep 19 '22 15:09

Waylan


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.

like image 38
Chris Avatar answered Sep 18 '22 15:09

Chris