Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

hexo-prism-plus

npm version npm dependencies Build Status

NPM

Better code block highlighting with Prism for Hexo, which exposes the full power of Prism with an elegent interface in markdown.

This is done by providing a custom before_post_render that replaces the original backtick code block. This package also includes a tag plugin that is similar to the original include_code tag, but works with Prism.

Demo

All code blocks in my blog are generated by this plugin. Please go and take a look. The source code is available on Github.

Installation

npm i -S hexo-prism-plus

This will install hexo-prism-plus and add it as a dependency in your package.json. In addition, in order to inject javascript and css to pages, hexo-inject is added as a dependency.

The default highlight is automatically disabled, so no more change is needed.

NOTE: for yarn user, please check if hexo-inject has been automatically added to the project dependency in package.json. hexo uses package.json to find available plugins, missing entry will cause hexo-inject not being loaded during generation.

NOTE: while hexo-inject is deprecated, it still work with Hexo 3.8.0. In the future it may be factored out.

Usage

Backtick Code Block

Just write code using fenced code block syntax as usual. Additional options for Prism can be specified either inline or using a preset defined inside the site config file _config.yml.

```python preset=mypreset lineno=True line=1-4,7
# some code
```

See wiki for detailed description for config options.

Tag Plugin

To insert code snippets from file with Prism highlight, use

{% includecode /path/to/file [inline options] %}

/path/to/file is relative to code_dir in _config.yml. And inline options have the same format as those used in backtick code blocks.