Github Markdown 代码块内的上标

Superscript within code block in Github Markdown

<sup></sup> 标签用于上标。创建代码块是通过反引号完成的。我遇到的问题是,当我尝试在代码块中创建上标时,它会打印出 <sup></sup> 标签,而不是格式化标签之间的文本。

如何正确设置反引号之间的上标文本格式?

Post解决方案编辑

期望的输出: A<sup>2</sup> 而不是 A<sup>2</sup>

这是expected behaviour:

Markdown wraps a code block in both <pre> and <code> tags.

您可以在代码块中使用 Unicode superscript and subscript characters

class SomeClass¹ {
}

输入这些字符将取决于您的操作系统和配置。我喜欢在我的 Linux 机器上使用 compose key 序列。作为最后的手段,您应该能够从上面提到的 Wikipedia 页面之类的内容中复制和粘贴它们。

¹一些有趣的脚注,例如在 <pre> and <code> 个标签上引用 MDN。

这是不可能的,除非你使用原始 HTML。

rules具体说明:

With a code span, ampersands and angle brackets are encoded as HTML entities automatically, which makes it easy to include example HTML tags.

换句话说,无法使用HTML 来格式化代码跨度中的文本。事实上,代码跨度是无格式的纯文本。将任何该文本显示为上标将意味着它不是纯文本、未格式化的文本。因此,这在设计上是不可能的。

但是,规则也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. ...

因此,如果您确实需要代码范围内的某些文本为上标,则对整个范围使用原始 HTML(请务必根据需要手动转义):

<code>A code span with <sup>superscript</sup> text and escaped characters: "&lt;&amp;&gt;".</code>

呈现为:

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

如果幸运的话,您想要上标(或下标)的字符可能在 Unicode 中有专用的代码点。这些将在代码块内工作,如您的问题所示,您在反引号中包含 。例如:

Water (chemical formula H₂O) is transparent, tasteless and odourless.

我已经在 this Gist 中列出了上标和下标 Unicode 字符。您应该能够从那里复制和粘贴您需要的任何内容。