Aaron Germano Alphonsus Aaron Germano Alphonsus - 4 months ago 25
Markdown Question

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>

Answer

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: "<&>".