博客踩坑日记

hexo+next踩坑日常

代码高亮组件

由于看到别人提到的默认代码高亮效果差,需要在根目录下用npm添加组件hexo-prism-plugin

1
$ npm i -S hexo-prism-plugin

结果会警告报错(不影响正常运行),实在看不下去了

1
$ ERROR Plugin load failed: hexo-prism-plugin

这是由于hexo5.0后的版本自带prismjs代码语法高亮的支持,解决方法也简单,进根目录git bash卸载就行,再去根目录_config.yml文件中搜highlight更改配置

1
$ npm uninstall hexo-prism-plugin
1
2
3
4
5
6
7
8
9
10
11
12
$ highlight:
enable: false #默认启用,禁用掉就行
line_number: true
auto_detect: false
tab_replace: ''
wrap: true
hljs: false
prismjs:
enable: true
preprocess: true
line_number: true
tab_replace: ''

默认主题prismjs是tomorrow night,如果要定制主题的话,可以前往prismjs官网下载自己喜欢的主题css文件,再将css主题文件改名为prism.css,替换掉hexo-theme-matery里的source/libs/prism/prism.css文件即可