为什么要更换 prismjs 代码高亮

prismjs 拥有更丰富的语言支持。

更换步骤

在自己新版的 Hexo(7.1.0) 中,配置如下:

1
2
3
4
5
syntax_highlighter: prismjs
prismjs:
preprocess: true
line_number: true
tab_replace: ''

只需将 syntax_highlighter 的值改为 prismjs 即可。

首次更换时需要清除缓存再运行 hexo clean && hexo s

更换效果

1
console.log('Hello World!');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract R4AGv2 {
string public name = "R4AGv2";
uint256 public totalSupply = 1000000000000000000000000; // 1 million tokens
address public owner;

mapping(address => uint256) public balanceOf;

constructor() {
balanceOf[msg.sender] = totalSupply;
owner = msg.sender;
}

function transfer(address to, uint256 amount) external {
require(balanceOf[msg.sender] >= amount, "Not enough tokens");

balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;
}
}
1
2
def hello():
print('Hello World!')
1
2
3
4
5
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
1
2
3
4
5
6
#include <stdio.h>

int main() {
printf("Hello World!\n");
return 0;
}
1
2
3
4
5
6
#include <iostream>

int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
1
2
3
4
5
6
7
8
9
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
1
2
3
body {
background-color: #f0f0f0;
}
1
title: Hello World
1
2
3
{
"title": "Hello World"
}
1
echo "Hello World!"
1
2
- Hello World!
+ Hello Hexo!
1
2
3
4
5
6
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.html;
}
1
# Hello World