gitbook-plugin-prism-ex v0.0.2
GitBook plugin for Prism with support for Prism plugins
This plugin hilights the syntax of code blocks using the Prism highlighter.
Rendering is performed at build time, NOT at runtime on the browser. This allows the plugin to also run when generating PDF books.
Prism plugins are also supported but, as rendering is done at build time, plugins that generate interactive elements will not work properly; they will render (even for PDFs), but no interactivity is supported.
Technical note: supporting Prism plugins on GitBook is not trivial, as they were designed for operation on the browser only, so a DOM representation of the document must be provided to them. This plugin provides such DOM trough an emulation that runs on NodeJS at build time, so that plugins operate as expected.
修改支持最新prismjs,支持PLSQL等语言。
Before
After
Usage
Add the plugin to your book.json, and disable default GitBook code highlighting:
{
"plugins": ["prism-ex", "-highlight"]
}Options
theme
Override the default syntax highlighting styles.
The CSS file path may be relative to the node_modules folder or to the book's source folder (if you want to provide a custom style that is bundled with the book's files instead of being provided by an installable module).
"pluginsConfig": {
"prism": {
"theme": "prismjs/themes/prism-solarizedlight.css"
}
}lang
Support non-standard syntax prefixes by aliasing existing prefixes.
"pluginsConfig": {
"prism": {
"lang": {
"flow": "typescript"
}
}
}ignore
Due to other plugins using code block notion to denote other functionality, you can ignore certain langs
"pluginsConfig": {
"prism": {
"ignore": [
"mermaid",
"eval-js"
]
}
}cssClasses
Appends a space-separated list of CSS classes to each fenced code block (those whose PRE element has a CODE element as a direct child).
This is meant to be used with some plugins that require a specific CSS class to be applied to the PRE element, in order for the plugin to be activated on that block.
"pluginsConfig": {
"prism": {
"cssClasses": "line-numbers"
}
}Prism Plugins
You may specify a list of Prism plugins on the pluginsConfig.prism.plugin configuration property on book.json.
That property should be an array where each element may be either:
- a string with the plugin name (ex: "line-numbers");
- an array of CSS and/or JS files; each file path may be relative to
node_modulesor to the book's source folder.
The simplest case
In this basic example, we're loading the line-numbers Prism plugin.
book.json
{
"plugins": ["-highlight", "prism-ex"],
"pluginsConfig": {
"prism": {
"plugins": ["line-numbers"],
"cssClasses": "line-numbers"
}
}
}Note: the
cssClassesvalue is required by this specific Prism plugin.
A more complex case
In this example, we're loading:
- the
line-numbersandshow-invisiblesPrism plugins, - a custom syntax theme from the
prism-ASHGitBook plugin, - a custom Prism plugin embedded on the book itself, on the
srcfolder, comprised of a CSS and a JS file.
book.json
{
"plugins": ["-highlight", "prism-ex", "prism-ASH"],
"pluginsConfig": {
"prism": {
"theme": "syntax-highlighting/assets/css/prism/prism-tomorrow-night-bright.css",
"plugins": ["line-numbers", "show-invisibles", ["src/my-plugin.css", "src/my-plugin.js"]],
"cssClasses": "line-numbers my-example-class"
}
}
}Prism Themes
https://github.com/PrismJS/prism
Okaidia prismjs/themes/prism-okaidia.css

Solarized Light prismjs/themes/prism-solarizedlight.css

Tomorrow prismjs/themes/prism-tomorrow.css

Dark prismjs/themes/prism-dark.css

Coy prismjs/themes/prism-coy.css

Atelierbram Themes
https://github.com/atelierbram/syntax-highlighting
Base16 Ocean Dark syntax-highlighting/assets/css/prism/prism-base16-ocean.dark.css

Google Light syntax-highlighting/assets/css/prism/prism-base16-google.light.css

Xonokai syntax-highlighting/assets/css/prism/prism-xonokai.css

Credits
Based on gaearon/gitbook-plugin-prism, which was based on google_code_prettify.
License
Apache 2