Markdown – General Markdown syntax and extensions

Markdown syntax

Reference documentation Reference documentation

This section introduces the concepts you need to know when writing using Markdown syntax.

Some syntax restrictions have been changed in Markdown Extra, don't forget to check out the Markdown Extra section below.

Outline

哲学

The purpose of Markdown is to be as easy to read and write as possible.

However, readability is emphasized above all other aspects. A Markdown-formatted document should be publishable as plain text, without being marked up with tags or formatting instructions. Although Markdown's syntax was influenced by several existing text-to-HTML filters, including Setext, atx, Textile, reStructuredText, Grutatext, and EtText, the biggest source of inspiration for Markdown's syntax was the format of plain text email.

To this end, Markdown's syntax consists entirely of punctuation marks that are carefully chosen to look like what they mean. For example, an asterisk around a word actually looks like *emphasis*. Markdown lists look just like lists. Assuming you've ever used email, even block quotes looked like quoted text paragraphs.

Inline HTML

You don't have to know HTML to use Markdown. But if you know some HTML tags, you can use them wherever you want. For example, to format some text as superscript (something not covered by Markdown syntax), you can use <sup> HTML markup.

Be cautious about what you read on April 1<sup>st</sup>!

Markdown will skip this tag without changing it, and the browser will display the text inside as superscript.


Be cautious about what you read on April 1st!


Block HTML element, for example,<div>,<table>,<pre>,<p> wait. They must be separated from surrounding content by blank lines, and the opening and closing tags of a block should not be indented with tabs or spaces.

Automatic escaping of special characters

In HTML, there are two characters that require special treatment.<& . The former is used for start tags, and the latter is used to represent HTML entities. If you want to use them as literal characters, you must escape them as entities, for example, <& . In Markdown they are automatically escaped.

block element

Paragraph

A paragraph is defined as one or more lines of text, each with at least one blank line in between.

这是一个说明 Markdown 如何工作的小段落。
这一段跨越了很多行。

这是第二个段落。

Below are the results.


This is a short paragraph explaining how Markdown works.
This paragraph spans many lines.

This is the second paragraph.


标题

In order to avoid damaging the structure of this article, the effects will not be displayed in this part.

You can add titles and subtitles to your documents using Markdown. Two syntaxes allow you to insert up to six different levels of headings. You can write level 1 and 2 headings using "SeText" syntax.

标题 1
========

标题 2
--------

The "atx" syntax can create any level of header by changing the number of pound signs (#).

# 标题 1 #

## 标题 2 ##

###### 6 级标题

Note that the trailing pound sign is optional.

引用

Maybe you've seen this way of referencing someone in an email discussion.

关于线性代数的一句话:

> 在现实生活中,稳定线性系统的解决方式有两种:
> 直接计算(例如使用矩阵因式分解)或通过迭代程序产生一串接近精确解的向量。

A word about linear algebra:

In real life, there are two ways to solve stable linear systems:
Compute directly (e.g. using matrix factorization) or through an iterative procedure to produce a sequence of vectors that is close to the exact solution.


List

Markdown helps you when creating ordered and unordered lists.
To create an ordered list, use a number followed by a dot as a marker.

1. 北京
2. 上海
3. 山东

  1. Beijing
  2. Shanghai
  3. Shandong

To create an unordered list, use *, +, or – as item markers.

- 太阳
- 月球
- 地球

  • 太阳
  • Moon
  • 地球

You can nest two-level lists by indenting them by a tab (or four spaces).

* 原料
    - 牛奶
    - 鸡蛋
* 产出
    1. 煎饼
    2. 饼干

  • 原料
    • milk
    • egg
  • output
    1. Pancakes
    2. Biscuits

If your list contains an entire paragraph, leave a blank line between list items. To write multiple paragraphs under the same list item, make sure they are indented by one tab (or four spaces).

1.  第一段。

    第二段。

2.  另一个列表项。

3.  又一个列表项。

  1. First paragraph.

    The second paragraph.

  2. Another list item.

  3. Another list item.


代码

We write a block of code by indenting some lines by one tab (or four spaces).

如何标记强调:

    使用 <em>HTML</em> 并使用 *Markdown* 。

Within the code block, you can use HTML tags or Markdown formatting, in both cases the syntax will not be parsed and the text will be displayed as-is.


How to mark emphasis:

使用 <em>HTML</em> 并使用 *Markdown* 。

Dividing line

You can create a horizontal dividing line by placing three or more *, +, or – in a line. If you wish, you can use spaces between *, +, or –. Each line below will produce a horizontal dividing line.

* * *

***

*****

- - -

---------------------------------------

They all represent the same dividing line.








fragment element

link

If you want to insert a hypertext link into your document, Markdown gives you two methods. You can write your links as inline links or reference links.

Inline links allow some text to be linked to another web page. Surround the link with [brackets], and then put the URL in the brackets.

[MyRedstone](https://www.myredstone.top/)

[MyRedstone](https://www.myredstone.top/ "我的网站")

MyRedstone

MyRedstone


The second link has a title that most web browsers display as a tooltip when your mouse hovers over the link. Title is optional.

Refence-style links work the same way, except you don't have to put the URL in the middle of the paragraph, which makes the text clearer. Instead, you give the link a name and write the URL on a separate line, anywhere in the document. It looks like this.

这是一篇来自 [MyRedstone][rs] 的文章。

 [rs]: https://www.myredstone.top/ "我的网站"

The line defining the URL is stripped from the final output, and the text in parentheses becomes a link.

Likewise, the title of the link (My Site) is optional.

Or you can use the following writing method, which does not require additional link names.

这是一篇来自 [MyRedstone][] 的文章。

 [MyRedstone]: https://www.myredstone.top/ "我的网站"

The effect is the same as the previous one.

This site does not support Refence writing.

Note that if the linked page is the same as the website where the Markdown is located, you can use relative paths, which is the example shown in "Pictures".

Emphasize

You can emphasize certain parts of your text within a paragraph. There are two types of emphasis, normal emphasis and strong emphasis. On most websites, normal emphasis appears in italics, while strong emphasis is in bold.

To add emphasis to some text in Markdown, we use an asterisk (*) or an underscore (_). Surrounding some text with an asterisk or an underline will give you normal emphasis, while surrounding some text with two asterisks or two underlines will give you strong emphasis.

*用星号的正常强调*

_用下划线的正常强调_

**用星号的强烈强调**

__用下划线的强烈强调__

这是一些用星号*强调*的文字。

Get this result.


Normal emphasis with an asterisk

Normal emphasis with underline

Strong emphasis with an asterisk

Use underline for strong emphasis

Here are some using asterisksEmphasizeText.


Note that there is absolutely no difference between using underscores and asterisks, the results are exactly the same. Please choose the one you are most familiar with.

代码

You can insert a code snippet in the middle of your paragraph by using backticks (`), like this. (Use single quotes instead because it shows an error)

请不要使用 '<blink>' 标签。

This will produce the following results.


please do not use <blink> label.


image

Admittedly, it is quite difficult to devise a "natural" syntax for putting images into a plain text document format.

Markdown uses a "link"-like method to reference images. You only need to add it before the link format. ! Just fine.

![MyRedstone](/wp-content/uploads/2019/02/redstone.png)

![MyRedstone](/wp-content/uploads/2019/02/redstone.png "我的网站")

The effect is as follows.


MyRedstone

MyRedstone


"MyRedstone" is the alternative text that will be displayed when the image fails to load. "My Website" is the same as the link and serves as the title of the image. When your mouse is over the image, most web browsers will display a tool tip. form display. Title is optional.

Reference-style link images are also supported and will not be shown here.

This site does not support Refence writing.

Miscellaneous

auto link

If you just want to be clickable on a URL inserted into your text, put the URL in angle brackets and Markdown will use it to make a clickable link.

<https://www.myredstone.top/>

<2824517378@qq.com>

https://www.myredstone.top/

2824517378@qq.com


backslash escaping

Markdown allows you to use backslash escaping to generate literal characters that would otherwise have special meaning in Markdown's formatting syntax. For example, if you want to surround a word with literal asterisks, you can use a backslash before the asterisk, like this.

\*字面星号\*

*literal asterisk*


Markdown provides backslash escaping for the following characters.

  • \ backslash
  • ` backtick
  • * Asterisk
  • _ underline
  • {} big parantheses
  • [] Square brackets
  • () Parentheses
  • # hashtag
  • + plus sign
  • – Minus sign (hyphen)
  • . point
  • ! exclamation mark

Markdown Extra syntax

Reference documentation

Inline HTML

With Markdown, you can insert HTML in the middle of your text. This is useful when you need some functionality that is not provided by Markdown syntax but is easily achieved using HTML.

But Markdown has a serious limitation when it comes to block elements. This can be seen from the Markdown syntax documentation.

Block HTML element, for example,<div>,<table>,<pre>,<p> wait. They must be separated from surrounding content by blank lines, and the opening and closing tags of a block should not be indented with tabs or spaces.

These restrictions have been removed in Markdown Extra and replaced by these two looser restrictions.

  1. The indentation of the opening tag of a block element cannot exceed three spaces. Because according to standard Markdown rules, any tag indented beyond this number will be considered a code block.

  2. When a block element is found within a list, all of its contents should be indented by the same amount of space as the list items.

Markdown within HTML blocks

Previously in Markdown, you couldn't wrap Markdown formatted content in <div> element. This is because <div> It is a block element, and ordinary Markdown does not format such content.

Markdown Extra provides you with a way to place Markdown-formatted text within any block element. You can do this by adding a Markdown attribute with a value of 1 on the tag, like this.

<div markdown="1">
这是 *真正的* Markdown 文本。
</div>

markdown="1" attributes will be stripped,<div> The content will be converted from Markdown to HTML. The result is this.


这 是 truly Markdown text.


Markdown Extra is smart enough to apply the correct formatting based on which block element you put the Markdown attribute on. For example, if you are in a <p> Apply the Markdown attribute to the tag, which will only generate fragment-level elements. It does not support lists, block references, and code blocks.

But there are some ambiguous situations, such as this case.

<table>
<tr>
<td markdown="1">这是 *真正的* Markdown 文本。</td>
</tr>
</table>

这 是 truly Markdown text.


A table cell can contain both fragment and block elements. In cases like this, Markdown Extra will only apply fragment-level rules. If you want to enable block element structure, just write markdown="block" Just fine.

Special attribute

With Markdown Extra, you can use a property block to set idclass Attributes. For example, put the required id , prefixed by a pound sign, like this.

标题 1            {#标题1}
========

## 标题 2 ##      {#标题2}

You can then create links to different parts of the same article like this.

[返回标题1](#标题1)

Use a dot like this to add a class name that can be used as a stylesheet hook.

## 网站 ##    {.main}

You can also add custom properties with simple values ​​in the format of the property name followed by an equal sign and the value. (Currently cannot contain spaces).

## 网站简介 ##    {lang=fr}

IDs, multiple class names, and other custom properties can be combined by putting them all into the same special properties block.

## 网站简介 ##    {.main .shine #the-site lang=fr}

Special property blocks can be combined with the following elements.

  • 标题
  • fence code block
  • link
  • image

For images and links, the special attribute block immediately follows the parentheses containing the address.

[link](url){#id .class}
![img](url){#id .class}

Or, if using Refence-style links and images, put it at the end of the definition line like this.

[link][linkref] or [linkref]
![img][linkref]

[linkref]: url "optional title" {#id .class}

This site does not support Refence writing.

fence code block

Markdown Extra introduces an unindented code block. Fence code blocks are just like regular code blocks in Markdown, except that they are not indented and rely on starting and ending fence lines to demarcate the boundaries of the code block. code block to contain three or more ~ characters and contain the same number of ~ The end of a line. For example

这是一个介绍的段落。

~~~~~~~~~~~~~~~~~~~~~
一个单行代码块
~~~~~~~~~~~~~~~~~~~~~

You can also use backtick backtick (\)来代替 ~`.

Contrary to indented code blocks, fenced code blocks can start and end with a blank line.

Indented code blocks cannot be used immediately after a list, because list indentation takes precedence, but fence code blocks have no such restriction.

You can specify a category name that applies to the code block. This is useful if you want to design different blocks of code for different languages. Or you can use it to tell the syntax highlighter what syntax it should use. Just add the language at the end of the first line of fences like cpp Or html, optionally placing a point in front of it. You can also use special attribute blocks.

form

Markdown Extra has its own syntax for simple tables. A "simple" table looks like this.

第一列标题 | 第二列标题
--------- | ---------
一个单元格 | 一个单元格
一个单元格 | 一个单元格

The first row contains the column headers, the second row contains the mandatory separator between the headers and the content, and each subsequent row is a row in the table. Columns are always separated by pipe (|) characters and the result is this.


First column title Second column title
a cell a cell
a cell a cell

If you want, you can add a leading and trailing pipe to each row of the table. You can use whichever format you prefer. Below is an example which will give the same result as above.

| 第一列标题 | 第二列标题 |
| --------- | --------- |
| 一个单元格 | 一个单元格 |
| 一个单元格 | 一个单元格 |

Note: A table needs to have at least one pipe on each row in order for Markdown Extra to parse it correctly. This means that the only way to create a single-column table is to add a leading or trailing pipe, or both, to each row.

You can specify the alignment of each column by adding a colon to the separator line. A colon to the left of the separator line will align the column to the left, a colon to the right of the separator line will align the column to the right, and colons on both sides mean that the column will be aligned to the center.

| 物品      |  价格  |
| --------- | ----: |
| 计算机    |  $1600 |
| 手机      |    $12 |
| 管材      |     $1 |

align HTML attributes are applied to each cell of the relevant column, producing the following effect.


article Price
CS $1600
Mobile phone $12
pipes $1

You can apply fragment-level formatting to the content of each cell using regular Markdown syntax.

| 函数名       | 描述                 |
| ------------ | ------------------- |
| 'help()'     | 显示帮助窗口。       |
| 'destroy()'  | **销毁你的计算机!** |

The effect is as follows.


Function name Description
help() Display the help window.
destroy() Destroy your computer!

definition list

Markdown Extra implements definition lists. A definition list is made up of terms and the definitions of those terms, much like a dictionary.

In Markdown Extra, a simple definition list consists of a single-line term followed by a colon and the definition of the term.

苹果
:   是蔷薇科苹果亚科
    苹果属植物。

橙子
:   是芸香科柑橘属植物橙树的果实。

Terms must be separated from the previous definition by a blank line. Definitions can span multiple lines, in which case they should be indented. But you don't have to do that, if you want to be lazy, you can forget to indent a definition that spans multiple lines and it will still work.

苹果
:   是蔷薇科苹果亚科
苹果属植物。

橙子
:   是芸香科柑橘属植物橙树的果实。

Each of the previous definition lists gives the same result.


apple
It is a subfamily of the family Rosaceae.
Malus plant.
orange
It is the fruit of the orange tree, a citrus plant in the family Rutaceae.

The colon used as a defining marker usually begins in the left margin, but may be indented by up to three spaces. The definition tag must be followed by one or more spaces or tabs.

A definition list can have more than one definition associated with a term.

苹果
:   是蔷薇科苹果亚科
    苹果属植物。
:   一家美国计算机公司。

橙子
:   是芸香科柑橘属植物橙树的果实。

The effect is as follows.


apple
It is a subfamily of the family Rosaceae.
Malus plant.
An American computer company.
orange
It is the fruit of the orange tree, a citrus plant in the family Rutaceae.

You can also associate more than one term with a definition.

术语 I
术语 II
:   定义 A

术语 III
:   定义 B

The effect is as follows.


Terminology I
Terminology II
Definition A
Terminology III
Definition B

And, just like regular list items, definitions can contain multiple paragraphs and include other block elements such as block quotes, code blocks, lists, and even other definition lists.

术语 I

:   这是一个有两段话的定义。

    这是他的第二段。

:   这是术语 I 的第二个定义。

术语 II

:   该定义包含一个代码块,一个区块引用和一个表列。

        代码块。

    > 区块引用。
    > 第二行。

    1.  第一个元素
    2.  第二个元素

The result is as follows.


Terminology I

This is a two-paragraph definition.

This is his second paragraph.

This is the second definition of the term I.

Terminology II

The definition contains a code block, a block reference and a table column.

代码块。

Block reference.
second line.

  1. first element
  2. second element

footnote

Footnotes work primarily like reference-style links. A footnote consists of two parts, a mark in the text, which will become a superscript number, and a footnote definition, which will be placed in the footnote list at the end of the file. A footnote looks like this.

这是一些带脚注的文字。[^1]

[^1]: 而这就是脚注。

Footnote definitions can be found anywhere in the document, but footnotes are always listed in the order in which they are linked in the text.

Each footnote must have a unique name. The name will be used to associate the footnote reference with the footnote definition but has no effect on the footnote numbering. Name can be included in HTML id Any valid characters in the attribute.

Footnotes can contain block elements, which means you can put multiple paragraphs, lists, block quotes, etc. in a footnote. It works the same as list items, just indent the paragraph below by four spaces in the footnote definition.

这是一些带脚注的文字。[^1]

[^1]: 而这就是脚注。

    这是第二段话。

If you want better alignment, you can leave the first line of the footnote blank and put your first paragraph below.

这是一些带脚注的文字。[^1]

[^1]:
    而这就是脚注。

    这是第二段话。

abbreviation

Markdown Extra adds support for abbreviations. How it works is very simple, create an abbreviation definition like this.

*[HTML]: 超文本标记语言
*[W3C]:  万维网联盟

Then, somewhere else in the file, write text like this.

HTML 规范是由 W3C 维护的。

His explanation pops up when you hover over the abbreviation.

Abbreviations are case-sensitive and, when defined as an abbreviation, can span multiple words. Abbreviations may also have an empty definition, as follows.

Ordered list

If an ordered list starts with a number other than 1, Markdown Extra will respect this in the output.

Emphasize

The rules for emphasis have changed slightly from the original Markdown syntax. In Markdown Extra, underscores in the middle of words are now treated as literal characters. Underline emphasis only applies to the entire word. If you only need to emphasize certain parts of a word, you can still do so by using an asterisk as an emphasis mark.

For example, in this case.

请打开 "secret_magic_box" 文件夹。

Markdown Extra does not convert underscores into emphasis because they are in the middle of the word. The result looks like this.


Please open the "secret_magic_box" folder.


As long as you emphasize the entire word like this, underlining the emphasis still works.

I like it when you say _you love me_.

The effect is as follows.


I like it when you say Tu m'aimes.


The same applies to strong emphasis, in Markdown Extra you cannot use an underscore to put strong emphasis in the middle of a word, you must use an asterisk as an emphasis mark.

backslash escaping

Markdown Extra adds colon (:) and pipe (|) to the list of characters you can escape with backslashes. With this you can prevent them from triggering definition lists or tables.

module

These modules are used on this website through special "code blocks".

Name Reference documentation grammar
KaTeX Reference documentation Use with katex a block code block named, or $$ Wrapped snippet code.
Mermaid Reference documentation Use with mermaid is the name of the block code block
flow chart Reference documentation Use with flow is the name of the block code block
Flowchart Reference documentation Use with seq is the name of the block code block

GFM worklist syntax

Worklist functionality for Github Flavored Markdown (GFM).

- [x] Finish my changes
- [ ] Push my commits to GitHub
- [ ] Open a pull request
  • Finish my changes
  • Push my commits to GitHub
  • Open a pull request

Githuber MD extended syntax

HTML5 Figure tag

%[Alt text](http://yoururl.com/test.jpg "Figcaption text")

The above Markdown text conversion result:

<figure>
    <img src="http://yoururl.com/test.jpg" alt="Alt text">
    <figcaption>Figcaption text</figcaption>
</figure>

Interline code blocks using keyboard styles

Happy using Markdown! ! !

  1. 使用 ctrl+c Copy text.
  2. 使用 ctrl+v Paste the text.
  3. Open task manager: ctrl+alt+del

Post Reply