mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
1590 字
8 分钟
markdown 语法支持测试 - 第二版
2024-11-18

Markdown: Syntax#

Note: This document is itself written using Markdown; from markdown-cheatsheet,markdown-test-file and gitlab-markdown-doc; you can see the source for it by adding ‘.text’ to the URL.


Overview#

Philosophy#

Markdown is intended to be as easy-to-read and easy-to-write as is feasible.

Readability, however, is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions. While Markdown’s syntax has been influenced by several existing text-to-HTML filters — including Setext, atx, Textile, reStructuredText, Grutatext, and EtText — the single biggest source of inspiration for Markdown’s syntax is the format of plain text email.

Block Elements#

Paragraphs and Line Breaks#

A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line — a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs.

The implication of the “one or more consecutive lines of text” rule is that Markdown supports “hard-wrapped” text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type’s “Convert Line Breaks” option) which translate every line break character in a paragraph into a <br /> tag.

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

Headers#

Markdown supports two styles of headers, [Setext] [1] and [atx] [2].

Optionally, you may “close” atx-style headers. This is purely cosmetic — you can use this if you think it looks better. The closing hashes don’t even need to match the number of hashes used to open the header. (The number of opening hashes determines the header level.)

Blockquotes#

Markdown uses email-style > characters for blockquoting. If you’re familiar with quoting passages of text in an email message, then you know how to create a blockquote in Markdown. It looks best if you hard wrap the text and put a > before every line:

This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.

Markdown allows you to be lazy and only put the > before the first line of a hard-wrapped paragraph:

This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.

Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by adding additional levels of >:

This is the first level of quoting.

This is nested blockquote.

Back to the first level.

Blockquotes can contain other Markdown elements, including headers, lists, and code blocks:

This is a header.#

  1. This is the first list item.
  2. This is the second list item.

Here’s some example code:

return shell_exec("echo $input | $markdown_script");

Any decent text editor should make email-style quoting easy. For example, with BBEdit, you can make a selection and choose Increase Quote Level from the Text menu.

Lists#

Markdown supports ordered (numbered) and unordered (bulleted) lists.

Unordered lists use asterisks, pluses, and hyphens — interchangably — as list markers:

  • Red
  • Green
  • Blue

is equivalent to:

  • Red
  • Green
  • Blue

and:

  • Red
  • Green
  • Blue

Ordered lists use numbers followed by periods:

  1. Bird
  2. McHale
  3. Parish

It’s important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. The HTML Markdown produces from the above list is:

If you instead wrote the list in Markdown like this:

  1. Bird
  2. McHale
  3. Parish

or even:

  1. Bird
  2. McHale
  3. Parish

you’d get the exact same HTML output. The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don’t have to.

To make lists look nice, you can wrap items with hanging indents:

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
  • Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.

But if you want to be lazy, you don’t have to:

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
  • Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.

List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab:

  1. This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.

    Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit.

  2. Suspendisse id sem consectetuer libero luctus adipiscing.

It looks nice if you indent every line of the subsequent paragraphs, but here again, Markdown will allow you to be lazy:

  • This is a list item with two paragraphs.

    This is the second paragraph in the list item. You’re only required to indent the first line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

  • Another item in the same list.

To put a blockquote within a list item, the blockquote’s > delimiters need to be indented:

  • A list item with a blockquote:

    This is a blockquote inside a list item.

To put a code block within a list item, the code block needs to be indented twice — 8 spaces or two tabs:

  • A list item with a code block:

    <code goes here>

Code Blocks#

Pre-formatted code blocks are used for writing about programming or markup source code. Rather than forming normal paragraphs, the lines of a code block are interpreted literally. Markdown wraps a code block in both <pre> and <code> tags.

To produce a code block in Markdown, simply indent every line of the block by at least 4 spaces or 1 tab.

This is a normal paragraph:

This is a code block.

Here is an example of AppleScript:

tell application "Foo"
beep
end tell

A code block continues until it reaches a line that is not indented (or the end of the article).

Within a code block, ampersands (&) and angle brackets (< and >) are automatically converted into HTML entities. This makes it very easy to include example HTML source code using Markdown — just paste it and indent it, and Markdown will handle the hassle of encoding the ampersands and angle brackets. For example, this:

<div class="footer">
&copy; 2004 Foo Corporation
</div>

Regular Markdown syntax is not processed within code blocks. E.g., asterisks are just literal asterisks within a code block. This means it’s also easy to use Markdown to write about Markdown’s own syntax.

tell application "Foo"
beep
end tell

Span Elements#

Markdown supports two style of links: inline and reference.

In both styles, the link text is delimited by [square brackets].

To create an inline link, use a set of regular parentheses immediately after the link text’s closing square bracket. Inside the parentheses, put the URL where you want the link to point, along with an optional title for the link, surrounded in quotes. For example:

This is an example inline link.

This link has no title attribute.

Emphasis#

Markdown treats asterisks (*) and underscores (_) as indicators of emphasis. Text wrapped with one * or _ will be wrapped with an HTML <em> tag; double *’s or _’s will be wrapped with an HTML <strong> tag. E.g., this input:

single asterisks

single underscores

double asterisks

double underscores

Code#

To indicate a span of code, wrap it with backtick quotes (`). Unlike a pre-formatted code block, a code span indicates code within a normal paragraph. For example:

Use the printf() function.

Math#

It’s possible to have math written with LaTeX syntax rendered using KaTeX.

This math is first inline \\(x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}\\).
This math is second inline $`E=mc^2`$
This is first separate line
$$x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$$
This is second separate line
```latex
x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
```

This math is first inline \(x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}\).

This math is second inline E=mc2`E=mc^2`

This is first separate line

x=b±b24ac2ax=\frac{-b\pm\sqrt{b^2-4ac}}{2a}

This is second separate line

x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}

Markdown Cheatsheet#


Heading 1#

Markup : # Heading 1 #
-OR-
Markup : ============= (below H1 text)

Heading 2#

Markup : ## Heading 2 ##
-OR-
Markup: --------------- (below H2 text)

Heading 3#

Markup : ### Heading 3 ###

Heading 4#

Markup : #### Heading 4 ####

Common text

Markup : Common text

Emphasized text

Markup : _Emphasized text_ or *Emphasized text*

Strikethrough text

Markup : ~~Strikethrough text~~

Strong text

Markup : __Strong text__ or **Strong text**

Strong emphasized text

Markup : ___Strong emphasized text___ or ***Strong emphasized text***

Named Link and http://www.google.fr/ or http://example.com/

Markup : [Named Link](http://www.google.fr/ "Named link title") and http://www.google.fr/ or <http://example.com/>

heading-1

Markup: [heading-1](#heading-1 "Goto heading-1")

Table, like this one :

First HeaderSecond Header
Content CellContent Cell
Content CellContent Cell
| First Header | Second Header |
| ------------ | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |

Adding a pipe | in a cell :

First HeaderSecond Header
Content CellContent Cell
Content Cell\
| First Header | Second Header |
| ------------ | ------------- |
| Content Cell | Content Cell |
| Content Cell | \ |

Left, right and center aligned table

Left aligned HeaderRight aligned HeaderCenter aligned Header
Content CellContent CellContent Cell
Content CellContent CellContent Cell
| Left aligned Header | Right aligned Header | Center aligned Header |
| :------------------ | -------------------: | :-------------------: |
| Content Cell | Content Cell | Content Cell |
| Content Cell | Content Cell | Content Cell |

code()

Markup : `code()`
var specificLanguage_code =
{
"data": {
"lookedUpPlatform": 1,
"query": "Kasabian+Test+Transmission",
"lookedUpItem": {
"name": "Test Transmission",
"artist": "Kasabian",
"album": "Kasabian",
"picture": null,
"link": "http://open.spotify.com/track/5jhJur5n4fasblLSCOcrTp"
}
}
}
Markup : ```javascript
```
  • Bullet list
    • Nested bullet
      • Sub-nested bullet etc
  • Bullet list item 2
Markup : * Bullet list
* Nested bullet
* Sub-nested bullet etc
* Bullet list item 2
-OR-
Markup : - Bullet list
- Nested bullet
- Sub-nested bullet etc
- Bullet list item 2
  1. A numbered list
    1. A nested numbered list
    2. Which is numbered
  2. Which is numbered
Markup : 1. A numbered list
1. A nested numbered list
2. Which is numbered
2. Which is numbered
  • An uncompleted task
  • A completed task
Markup : - [ ] An uncompleted task
- [x] A completed task
  • An uncompleted task
    • A subtask
Markup : - [ ] An uncompleted task
- [ ] A subtask

Blockquote

Nested blockquote

Markup : > Blockquote
>> Nested Blockquote

Horizontal line :


Markup : - - - -

Image with alt :

picture alt

Markup : ![picture alt](http://via.placeholder.com/200x150 "Title is optional")

Foldable text:

Title 1

Content 1 Content 1 Content 1 Content 1 Content 1

Title 2

Content 2 Content 2 Content 2 Content 2 Content 2

Markup : <details>
<summary>Title 1</summary>
<p>Content 1 Content 1 Content 1 Content 1 Content 1</p>
</details>
<h3>HTML</h3>
<p> Some HTML code here </p>

Link to a specific part of the page:

Go To TOP

Markup : [text goes here](#section_name)
section_title<a name="section_name"></a>

Hotkey:

⌘F

⇧⌘F

Markup : <kbd>⌘F</kbd>

Hotkey list:

KeySymbol
Option
Control
Command
Shift
Caps Lock
Tab
Esc
Power
Return
Delete
Up
Down
Left
Right

Emoji:

:exclamation: Use emoji icons to enhance text. :+1: Look up emoji codes at emoji-cheat-sheet.com

Markup : Code appears between colons :EMOJICODE:

支持与分享

如果这篇文章对你有帮助,欢迎支持作者或分享给更多人

markdown 语法支持测试 - 第二版
https://blog.souloss.com/posts/language/markdown-syntax/
作者
tester
发布于
2024-11-18
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

相关文章 智能推荐
1
系列导读
容器运行时 本系列从 Linux 内核的 Namespace、Cgroup、OverlayFS 出发,深入 OCI 规范、runc 源码、containerd 架构,再到容器安全、沙箱运行时、网络、存储、镜像构建、Wasm 容器,最后综合实战构建一个迷你容器运行时——从「会用 Docker」到「理解容器运行时的每一行代码」,每章配有可运行的代码示例与架构图,让你从容器用户进阶到容器运行时工程师。
2
综合实战:构建一个迷你容器运行时
容器运行时 综合实战——用 Go 从零构建一个迷你容器运行时——实现 Namespace 隔离(PID/Mount/UTS/IPC/Network)、Cgroup 资源限制(CPU/内存)、OverlayFS 分层文件系统、OCI Bundle 解析,最终实现一个能运行容器的 minirunc。将前 15 章的知识融会贯通,从「理解原理」到「动手实现」。
3
容器在 Kubernetes 中
容器运行时 深入容器在 Kubernetes 中的运行机制——CRI 接口、Pod Sandbox 创建、多容器模式、Init Container、Sidecar 注入,以及 kubelet 如何通过 CRI 与容器运行时交互。
4
Wasm 容器:WasmEdge/WASI
容器运行时 WebAssembly(Wasm)正在从浏览器走向服务器——WASI(WebAssembly System Interface)定义了 Wasm 访问操作系统的标准接口,WasmEdge/runwasi 等运行时让 Wasm 模块可以作为容器运行。详细解读 Wasm 容器的架构、WASI 接口、与 OCI 的集成、与 Linux 容器的对比——从「Wasm 只能在浏览器运行」到「Wasm 是下一代容器运行时」。
5
镜像构建:BuildKit
容器运行时 BuildKit 是 Docker 的新一代镜像构建引擎,支持并行构建、缓存导入导出、多阶段构建优化、secret 挂载等高级特性。从零讲透 BuildKit 的架构设计、Dockerfile 指令的执行原理、多阶段构建、缓存策略、以及如何编写高效的 Dockerfile——从「会写 Dockerfile」到「理解每一条指令的构建机制」。