Markdown-代码语法

Markdown-代码语法

简单表示

markdown拥有在md文本中按照代码语法渲染代码高亮的能力,要将单词或短语表示为 “代码” ,请将其包裹在反引号( ` ) 中,该符号在您键盘左上角,ESC 按键的下方,您可以通过切换至 英文输入法 直接点击键盘将其敲出。

Markdown语法 HTML 预览效果
At the command prompt, type `nano`. At the command prompt, type <code>nano</code>. At the command prompt, type nano.

转义反引号

如果你要表示为代码的单词或短语中包含一个或多个反引号,则可以通过将单词或短语包裹在双反引号( `` )中。

Markdown语法 HTML 预览效果
``Use `code` in your Markdown file.`` <code>Use `code` in your Markdown file.</code> Use `code` in your Markdown file.

插入指定编程语言的代码块

如果您希望在您的markdown文本中插入指定编程语言的代码块并渲染该语言类型的代码高亮,您可以使用:``` + 语言名

以三个  `  开始 + 语言名

您的代码块

以三个  `  结束

例如,假设您希望在您的markdown文本中插入 C++ 类型的代码块,并希望其高亮,则您可以按照如下的方式:

在markdown文本中,其渲染结果如下:

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout << "just like this!" << endl;
}

当然,您也可以使用 ~ 代替 ` ,在渲染代码块这个方面,其效果其实是一样的,您可以通过按住 shift + ` 将其敲出。

最终的渲染结果如下:

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout << "the same function as ` " << endl;
}

上一篇
下一篇