hexo博客插件之hexo-prism-plugin(代码高亮)


1. 安装

由于 Hexo 自带的代码高亮主题显示不好看,所以主题中使用到了 hexo-prism-pluginHexo 插件来做代码高亮,安装命令如下:

npm i -S hexo-prism-plugin

2. 用法

然后,修改 Hexo 根目录下 _config.yml 文件中 highlight.enable 的值为 false,并新增 prism 插件相关的配置,主要配置如下:

highlight:
  enable: false        //确保禁用默认代码高亮插件

prism_plugin:
  mode: 'preprocess'    // realtime/preprocess
  theme: 'tomorrow'
  line_number: false    // default false
  custom_css:             //optional

3. 运行

修改完成之后运行以下命令清理并重新生成项目:

hexo clean  #清除缓存

hexo generate  //可简写为  hexo g  生成静态网页

hexo server  #启动本地服务器,用于预览主题。

hexo deploy  #可简写为 hexo d  自动生成网站静态文件,并将本地数据部署到设定的仓库(如github)

4. 选项

  1. mode
  • realtime (Parse code on browser in real time)
  • preprocess (Preprocess code in node)
  1. theme
  • coy
  • default
  • dark
  • funky
  • okaidia
  • solarizedlight
  • tomorrow
  • twilight
  • atom-dark
  • base16-ateliersulphurpool.light
  • cb
  • duotone-dark
  • duotone-earth
  • duotone-forest
  • duotone-light
  • duotone-sea
  • duotone-space
  • ghcolors
  • hopscotch
  • pojoaque
  • vs
  • xonokai
  1. line_number
  • true (Show line numbers)
  • false (Default, Hide line numbers)
  1. no_assets
  • true (Stop loading asset files)
  • false (Default, load script and stylesheets files)

5. 问题

该插件目前还存在一定的问题,很多使用者反应无法实现其themeline_number效果 ,同样,我也遇到了这个问题,我的问题是,无法改变theme效果 无论改成什么主题,都是展示dark效果,line_number更是没有出现过.

这个问题还有待商榷……目前先使用hexo自带的代码高亮(个人感觉很丑)


文章作者: Xin.Zhao
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Xin.Zhao !
评论
  目录