主要分享一下 Hexo 中代码块的高级用法……

方式一: 使用“codeblock”代码块

1
2
3
{% codeblock [lang:language] [title] [url] [link text] %}
代码内容
{% endcodeblock %}

从左到右一一对应: 语言 标题 源码文件下载地址 下载地址的文字
以下是例子

Cpp Hello WorldDownload
1
2
3
4
5
6
7
#include<iostream>;
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
1
2
3
4
5
6
7
8
9
{% codeblock Cpp Hello World lang:cpp http://test1.com/helloworld.cpp Download %}
#include<iostream>;
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
{% endcodeblock %}

方式二: 使用“反引号”代码块

1
2
3
``` [language] [title] [url] [link text]
代码内容
```

反引号内内容含反引号

只需引号外比引号内多即可
比如

1
2
3
4
5
6
7
8
````4
```3
``2
`1
`
``
```
````