洛谷新渲染教程

· · 科技·工程

文章看似短小,却有 8363 字符,建议看完。

::::info[部分行高亮]

语法

代码框语言名称后面加上 lines=要高亮的行,可以用逗号分隔,减号表示连续多行

代码框语言名称后面加上 line-numbers,可以开启行号显示。

示例

line 1
line 2
line 3
line 4
line 5
line 6
未开启行号显示
开启行号显示

:::success[源代码]

```plain lines=1,4-5
line 1
line 2
line 3
line 4
line 5
line 6
未开启行号显示
```‮
```plain line-numbers
开启行号显示
```‮
:::

::::info[表格合并]

语法

在表格前面加上 ::cute-table{tuack} ,可以获得类似 Tuack 的表格。

在表格单元格中单独写一个 ^,表示和同一列中上一个非 ^ 单元格合并,并垂直居中。

在表格单元格中单独写一个 <,表示和同一行中上一个非 < 单元格合并,并水平居中。

我顺带发现了一个我以前不知道的小知识:在表格第二行,也就是表头下面那行,如果是 --- 或 :---,默认靠左显示;如果是 :---:,代表整一列水平居中;如果是 ---:,就是靠右对齐。

示例

测试点 n m 特殊性质
1 \le 10 \le 10 无
2 ^ ^ ^
3 ^ ^ ^
4 \le 3\times10^5 ^ ^
5 ^ ^ ^
6 ^ \le 3\times10^5 ^
7 ^ ^ ^
8 ^ ^ ^
9 =114514 < ^
10 ^ ^ ^

:::align{center} 类似 Tuack 的表格: ::: ::cute-table{tuack} |测试点|n |m |特殊性质| |-----|:---------------:|:---------------:|:----:| |1 |\le 10 |\le 10 |无 | |2 |^ |^ |^ | |3 |^ |^ |^ | |4 |\le 3\times10^5|^ |^ | |5 |^ |^ |^ | |6 |^ |\le 3\times10^5|^ | |7 |^ |^ |^ | |8 |^ |^ |^ | |9 |=114514 |< |^ | |10 |^ |^ |^ | :::success[源代码]

|测试点|$n$              |$m$              |特殊性质|
|-----|:---------------:|:---------------:|:----:|
|1    |$\le 10$         |$\le 10$         |无    |
|2    |^                |^                |^     |
|3    |^                |^                |^     |
|4    |$\le 3\times10^5$|^                |^     |
|5    |^                |^                |^     |
|6    |^                |$\le 3\times10^5$|^     |
|7    |^                |^                |^     |
|8    |^                |^                |^     |
|9    |$=114514$        |<                |^     |
|10   |^                |^                |^     |
:::align{center}
类似 Tuack 的表格:
:::‮
::cute-table{tuack}
|测试点|$n$              |$m$              |特殊性质|
|-----|:---------------:|:---------------:|:----:|
|1    |$\le 10$         |$\le 10$         |无    |
|2    |^                |^                |^     |
|3    |^                |^                |^     |
|4    |$\le 3\times10^5$|^                |^     |
|5    |^                |^                |^     |
|6    |^                |$\le 3\times10^5$|^     |
|7    |^                |^                |^     |
|8    |^                |^                |^     |
|9    |$=114514$        |<                |^     |
|10   |^                |^                |^     |
:::

::::info[居中对齐]

语法

:::align{center}
要居中对齐的文字
:::

要注意:center 不要写成 centre。

示例

:::align{center} 『时空无垠地延长』
— Time and space extend endlessly —
『维度被悄悄埋葬』
— Dimensions are quietly buried—
『歌者在星空的边缘吟唱』
— The singer chanted at the edge of the starry sky—
『永恒的毁灭乐章』
— Eternal music of destruction—
『在文明挣扎万年的地方』
— In a place where civilization has struggled for thousands of years—
『三颗恒星布撒不恒定的光』
— Three stars cast non−constant light—
『乐土般的天堂』
— Paradise—
『卑微的虫子企图染指神之权杖』
— The lowly bugs attempt to infect the scepter of God—
『天真的孩子手握烛棒』
— Naive children hold candlesticks in their hands—
『黑暗森林中的穿行』
— Walk through the dark forest—
『满眼皆是骸骨与伤』
— Eyes full of skeletons and wounds—
『熄灭的火光蔓延着恐惧与凄凉』
— The extinguished flame spread fear and desolation—
『童话的世界被绘进画里』
— The world of fairy tales is painted in the painting—
『被迫远走的游子在时间之外流浪』
— The wanderer , forced to go away , wanders outside of time—
『在无尽的星河浩渺里』
— In the vastness of the endless galaxy—
『孤独迷航』
— Lonely Trek—
『人类的墓碑』
— Man's tombstone—
『被印拓在宇宙最低的地方』
— It is in the lowest place in the universe—
『永远尘封的文明』
— A civilization that will always be dusty—
『陪葬着二维的太阳』
— Buried with the two− dimensional sun—
『正在死去的宇宙』
— The universe that is dying—
『归零重生的希望』
— The hope of zero rebirth—
『散逸的死线曲率的逃亡』
— The escape of the loose dead−line curvature—
『宇宙之外的人性却悄然绽放』
— The humanity of the universe outside the universe has quietly blossom—
『当时间消融了一切印记』
— When time dissolves all imprints—
『爱情却横跨了亿万年的离殇』
— Love spans hundreds of millions of years of death—
::: :::success[源代码]

:::align{center}
『时空无垠地延长』  
— Time and space extend endlessly —  
『维度被悄悄埋葬』  
— Dimensions are quietly buried—  
『歌者在星空的边缘吟唱』  
— The singer chanted at the edge of the starry sky—  
『永恒的毁灭乐章』  
— Eternal music of destruction—  
『在文明挣扎万年的地方』  
— In a place where civilization has struggled for thousands of years—  
『三颗恒星布撒不恒定的光』  
— Three stars cast non−constant light—  
『乐土般的天堂』  
— Paradise—  
『卑微的虫子企图染指神之权杖』  
— The lowly bugs attempt to infect the scepter of God—  
『天真的孩子手握烛棒』  
— Naive children hold candlesticks in their hands—  
『黑暗森林中的穿行』  
— Walk through the dark forest—  
『满眼皆是骸骨与伤』  
— Eyes full of skeletons and wounds—  
『熄灭的火光蔓延着恐惧与凄凉』  
— The extinguished flame spread fear and desolation—  
『童话的世界被绘进画里』  
— The world of fairy tales is painted in the painting—  
『被迫远走的游子在时间之外流浪』  
— The wanderer , forced to go away , wanders outside of time—  
『在无尽的星河浩渺里』  
— In the vastness of the endless galaxy—  
『孤独迷航』  
— Lonely Trek—  
『人类的墓碑』  
— Man's tombstone—  
『被印拓在宇宙最低的地方』  
— It is in the lowest place in the universe—  
『永远尘封的文明』  
— A civilization that will always be dusty—  
『陪葬着二维的太阳』  
— Buried with the two− dimensional sun—  
『正在死去的宇宙』  
— The universe that is dying—  
『归零重生的希望』  
— The hope of zero rebirth—  
『散逸的死线曲率的逃亡』  
— The escape of the loose dead−line curvature—  
『宇宙之外的人性却悄然绽放』  
— The humanity of the universe outside the universe has quietly blossom  
『当时间消融了一切印记』  
— When time dissolves all imprints—  
『爱情却横跨了亿万年的离殇』  
— Love spans hundreds of millions of years of death—  
:::‮
:::

::::info[靠右对齐]

语法

:::align{right}
要靠右对齐的文字
:::

示例

:::align{right} 时空无垠地延长
维度被悄悄埋葬
歌者在星空的边缘吟唱
永恒的毁灭乐章
在文明挣扎万年的地方
三颗恒星布撒不恒定的光
乐土般的天堂
卑微的虫子企图染指神之权杖
天真的孩子手握烛棒
黑暗森林中的穿行
满眼皆是骸骨与伤
熄灭的火光蔓延着恐惧与凄凉
童话的世界被绘进画里
被迫远走的游子在时间之外流浪
在无尽的星河浩渺里
孤独迷航
人类的墓碑
被印拓在宇宙最低的地方
永远尘封的文明
陪葬着二维的太阳
正在死去的宇宙
归零重生的希望
散逸的死线曲率的逃亡
宇宙之外的人性却悄然绽放
当时间消融了一切印记
爱情却横跨了亿万年的离殇
::: :::success[源代码]

:::align{right}
时空无垠地延长  
维度被悄悄埋葬  
歌者在星空的边缘吟唱  
永恒的毁灭乐章  
在文明挣扎万年的地方  
三颗恒星布撒不恒定的光  
乐土般的天堂  
卑微的虫子企图染指神之权杖  
天真的孩子手握烛棒  
黑暗森林中的穿行  
满眼皆是骸骨与伤  
熄灭的火光蔓延着恐惧与凄凉  
童话的世界被绘进画里  
被迫远走的游子在时间之外流浪  
在无尽的星河浩渺里  
孤独迷航  
人类的墓碑  
被印拓在宇宙最低的地方  
永远尘封的文明  
陪葬着二维的太阳  
正在死去的宇宙  
归零重生的希望  
散逸的死线曲率的逃亡  
宇宙之外的人性却悄然绽放  
当时间消融了一切印记  
爱情却横跨了亿万年的离殇  
:::‮
:::

::::info[引言]

语法

:::epigraph[引言来源]
引言内容
:::

示例

:::epigraph[—— \texttt{Linus Torvalds}]

\text{Talk is cheap, show me the code.}

::: :::success[源代码]

:::epigraph[—— $\texttt{Linus Torvalds}$]
$\text{Talk is cheap, show me the code.}$
:::‮
:::

::::info[折叠框]

语法

默认关闭的折叠框:

:::折叠框类型[折叠框标题(可省略)]
折叠框内容
:::

默认展开的折叠框:

:::折叠框类型[折叠框标题(可省略)]{open}
折叠框内容
:::

折叠框同样支持嵌入公式,甚至嵌套折叠框。

示例

:::error[这是 error 折叠框]{open} 不要打开蓝色折叠框! ::: :::info[这是 info 折叠框] 不要打开黄色折叠框! ::: :::warning[这是 warning 折叠框] :::warning[不要打开!] 千万别看绿色折叠框! ::: :::success[这是 success 折叠框] :::success[不要打开!] :::success[不要打开!] :::success[不要打开!] :::

:::success[源代码]

:::error[这是 `error` 折叠框]{open}
不要打开蓝色折叠框!
:::‮
:::info[这是 `info` 折叠框]
不要打开黄色折叠框!
:::‮
:::warning[这是 `warning` 折叠框]
:::warning[不要打开!]
千万别看绿色折叠框!
:::‮
:::success[这是 `success` 折叠框]
:::success[不要打开!]
:::success[不要打开!]
:::success[不要打开!]
![](bilibili:BV1GJ411x7h7)
:::‮
:::

::::info[小知识]

关于嵌套折叠框的实现

我目前发现两种实现方法:

:::info[1]
:::success[2]
内容
:::‮
::::info[1]
:::success[2]
内容
:::‮
::::‮

它们的效果都是一样的: :::info[1] :::success[2] 内容 ::: 别问我怎么发现的,我博客也有类似的提示框,自己研究出来的。

关于新渲染的其他特性

1. 未指定语言,自动识别成 c++ 语言

就比如你打一个代码框,忘记指定代码语言:

```‮
#include<bits/stdc++.h>
using namespace std;
int main(){
  cout<<"Hello world!";
  return 0;

}
```‮

原版的渲染是这样的:

#include<bits/stdc++.h>
using namespace std;
int main(){
  cout<<"Hello world!";
  return 0;

}

现在的渲染是这样的:

#include<bits/stdc++.h>
using namespace std;
int main(){
  cout<<"Hello world!";
  return 0;

}

2. 使用不能识别的语言作为普通文本

没看出加上这个后和原版有什么区别,就是如果指定代码框的语言是渲染器不认识的,就什么颜色都不渲染,纯黑文本。

就像这样:

这是纯黑文本

:::success[源代码]

```asdfghjkl//我乱打的
这是纯黑文本
```‮

:::

如何在代码框里完整打出 ::: ``` 等字符

如果你想在 Markdown 的代码框里打出这些字符,但是有不小心和代码框外的同类字符互相匹配了怎么办?

只需在这些符号后面加上一个特殊字符‮:E202edocinU

没错,这是个透明字符,虽然看不见,但它会阻止某些符号的互相匹配。

可以看到原本的代码框并不能正确匹配。

在加上这个字符(图中显示为红点)之后,代码框就能想我们想的那样子一样正确匹配了。

你说这个透明字符很难复制?

‮

洛谷的代码框在右上角新加了复制按钮,点击即可复制。

:::info[悄悄告诉你] 这是个控制字符,后面的字都会反转,所以不要在它后面写字哦!

‮这是个控制字符,后面的字都会反转,所以不要在它后面写字哦!

除了以上方法外,还有一个方法:

事实上可以打出``` :::等字符,只不过稍微费事一点:

感谢 @Alex866 提供的方法。

::::

好了这就是这篇教程的全部了。我写了好几个小时,希望能帮到你。