Giter Club home page Giter Club logo

gitbook-plugin-prism's Introduction

Gitbook Plugin for Prism

NPM

Before

After

Usage

Add the plugin to your book.json, and disable default GitBook code highlighting:

{
  "plugins": ["prism", "-highlight"]
}

Options

css

Override default styles. All css files must reside in the same folder.

"pluginsConfig": {
  "prism": {
    "css": [
      "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"
    ]
  }
}

Prism Themes

https://github.com/PrismJS/prism

Okaidia prismjs/themes/prism-okaidia.css

Okaidia

Solarized Light prismjs/themes/prism-solarizedlight.css

Solarized Light

Tomorrow prismjs/themes/prism-tomorrow.css

Tomorrow

Dark prismjs/themes/prism-dark.css

Dark

Coy prismjs/themes/prism-coy.css

Coy

Atelierbram Themes

https://github.com/atelierbram/syntax-highlighting

Base16 Ocean Dark syntax-highlighting/assets/css/prism/prism-base16-ocean.dark.css

Base16 Ocean Dark

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

Google Light

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

Google Light

Credits

Originally based on https://github.com/spricity/google_code_prettify.

License

Apache 2

gitbook-plugin-prism's People

Contributors

aarono avatar bebraw avatar firede avatar gaearon avatar howlowck avatar jevakallio avatar rlmv avatar robmcguinness avatar samypesse avatar soreine avatar timelyportfolio avatar ty- avatar viggyprabhu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gitbook-plugin-prism's Issues

Error with cpp code

Can you help me with an error please?
I get an error like this:

Failed to load prism syntax: cpp
TypeError: Cannot set property 'keyword' of undefined
    at Object.extend (/Users/mathbunnyru/Documents/work/documentation/node_modules/prismjs/prism.js:79:15)
    at Object.<anonymous> (/Users/mathbunnyru/Documents/work/documentation/node_modules/prismjs/components/prism-cpp.js:1:101)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.code (/Users/mathbunnyru/Documents/work/documentation/node_modules/gitbook-plugin-prism/index.js:64:11)

Failed to load prism syntax: objc

Running v2.2.0 I receive the following error:

screen shot 2017-06-21 at 2 05 46 pm

I am in no way using or attempting to load objective c syntax highlighting. Is there a way to silence the warnings or not include objc?

prism warnings & Failed to load prism syntax: text error

warn: "options" property is deprecated, use config.get(key) instead
warn: "options.generator" property is deprecated, use "output.name" instead
Failed to load prism syntax: text
{ Error: Cannot find module 'prismjs/components/prism-text.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at requireSyntax (/Users/s0d00px/electrode/node_modules/gitbook-plugin-prism/index.js:31:3)

    at Object.code (/Users/s0d00px/electrode/node_modules/gitbook-plugin-prism/index.js:97:11)
    at Record.TemplateBlock.applyBlock (/Users/s0d00px/.gitbook/versions/3.2.2/lib/models/templateBlock.js:205:23)
    at /Users/s0d00px/.gitbook/versions/3.2.2/lib/output/getModifiers.js:56:33
    at /Users/s0d00px/.gitbook/versions/3.2.2/lib/output/modifiers/highlightCode.js:47:24
    at /Users/s0d00px/.gitbook/versions/3.2.2/lib/output/modifiers/editHTMLElement.js:11:16 code: 'MODULE_NOT_FOUND'
}

Can't make it work

I'm new to both this plugin and gitbook.

I've tried to install this plugin by editing my book.json like this:

{
  "root": "./docs/",
  "plugins": ["prism", "-highlight"]
}

It doesn't work, the syntax highlighting is still the default one from Gitbook and the languages supported by prism and not the default Gitbook's highlight doesn't hightlight at all...

Is there anything else to do to install this plugin?

Expanding to support other languages

I looked into making Prism work in a generic way in a similar plugin. The primary problem is shown below:

> Object.keys(prism.languages)
[ 'extend',
  'insertBefore',
  'DFS',
  'markup',
  'css',
  'clike',
  'javascript' ]

Prism actually supports a ton of languages. Unfortunately I cannot see an easy way to access them through Node. I am not entirely sure why the entry point looks like that. It's possible I'm missing something here.

One way to "solve" this would be to set up a package that contains the language definitions in an easy to consume format. Of course there would be extra maintenance as it's easy to get out of sync with the main project.

Ideas are welcome as I would love to solve this somehow.

Version 2.0.0 introduces weird backgrounds in code blocks

I just tried building new offline versions of the redux docs (https://github.com/paulkogel/redux-offline-docs) and noticed the following problem with version 2.0.0 (/cc @robmcguinness):

Screenshot from the PDF (no text highlighting by the user!):

screen shot 2016-11-19 at 22 48 59


There was no mouse interaction but the text in the code block looks kind of highlighted.
After reverting to gitbook-plugin-prism 1.1.0 the backgrounds disappeared.

here are my installed packages:
Node version: 7.0.0
Gitbook CLI version: 2.3.0
GitBook version: 3.2.1

Gitbook plugins:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

TypeError: Cannot read property 'name' of undefined

install prism plugin occurs error:
gitbook -d serve
TypeError: Cannot read property 'name' of undefined
at module.exports.hooks.init (/Users/sunlili/workspace/book/node_modules/gitbook-plugin-prism/index.js:120:46)
at /Users/sunlili/.gitbook/versions/2.4.3/lib/plugin.js:162:25
at _fulfilled (/Users/sunlili/.gitbook/versions/2.4.3/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/Users/sunlili/.gitbook/versions/2.4.3/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/Users/sunlili/.gitbook/versions/2.4.3/node_modules/q/q.js:749:13)
at /Users/sunlili/.gitbook/versions/2.4.3/node_modules/q/q.js:810:14
at flush (/Users/sunlili/.gitbook/versions/2.4.3/node_modules/q/q.js:108:17)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)

gitbook -V
CLI version: 2.3.0
GitBook version: 2.4.3

book.json:

{
"plugins": ["prism", "-highlight"],
"pluginsConfig": {
"prism": {
"css": [
"prismjs/themes/prism-okaidia.css"
]
}
}
}

Breaks syntax highlighting in PDF :(

Dan, since you introduced this plugin to redux's docs, the syntax highlighting in the offline versions is gone :(

before:
screen shot 2015-09-21 at 10 26 31

after:
screen shot 2015-09-21 at 10 29 40

checked the PDF and ePub. assume it's the same for mobi.
any clue what might have caused this?

C# mapping is not required

Currently the csharp is mapped to cs and the plugin tries to load prismjs/components/prism-cs.js. However, prism.js has it as prismjs/components/prism-csharp.js.

Suggestion is to revert the mapping (cs->csharp) or remove the mapping.

warn: "options.generator" property is deprecated, use "output.name" instead

index.js#39L

function isEbook(book) {
  // 2.x
  if (book.options && book.options.generator) {
    return book.options.generator === 'ebook';
  }

  // 3.x
  return book.output.name === 'ebook';
}

book.options.generator is a get/set,you could change to

function isEbook(book) {
  // 2.x
  if (/^2+\.\d+\.\d+$/.test(book.gitbook.version)) {
    return book.options.generator === 'ebook';
  }
  return book.output.name === 'ebook';
}

Error: Cannot find module 'prismjs/components/prism-yml.js'

gitbook version 3.2.3

{ Error: Cannot find module 'prismjs/components/prism-yml.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at requireSyntax (/myBook/node_modules/gitbook-plugin-prism/index.js:31:3)
    at Object.code (/myBook/node_modules/gitbook-plugin-prism/index.js:103:11)
    at Record.TemplateBlock.applyBlock (/root/.gitbook/versions/3.2.3/lib/models/templateBlock.js:205:23)
    at /root/.gitbook/versions/3.2.3/lib/output/getModifiers.js:56:33
    at /root/.gitbook/versions/3.2.3/lib/output/modifiers/highlightCode.js:47:24
    at /root/.gitbook/versions/3.2.3/lib/output/modifiers/editHTMLElement.js:11:16 code: 'MODULE_NOT_FOUND' }
Failed to load prism syntax: yml
{ Error: Cannot find module 'prismjs/components/prism-yml.js'

gitbook serve fail

$ gitbook -V
CLI version: 2.3.0
GitBook version: 3.2.2

$ gitbook serve ./ --debug
Live reload server started on port: 35729
Press CTRL+C to quit ...

info: 16 plugins are installed
info: 14 explicitly listed
info: loading plugin "splitter"... OK
info: loading plugin "github"... OK
info: loading plugin "prism"... OK
info: loading plugin "expandable-chapters"... OK
info: loading plugin "anchors"... OK
info: loading plugin "anchor-navigation-ex"... OK
info: loading plugin "advanced-emoji"... OK
info: loading plugin "bootstrap-callout"... OK
info: loading plugin "livereload"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 8 pages
info: found 11 asset files
Failed to load prism syntax: javasrcipt
{ Error: Cannot find module 'prismjs/components/prism-javasrcipt.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.code (f:\note\gitbook\vue-note\node_modules\gitbook-plugin-prism\index.js:64:11)
    at Record.TemplateBlock.applyBlock (C:\Users\Administrator\.gitbook\versions\3.2.2\lib\models\templateBlock.js:205:23)
    at C:\Users\Administrator\.gitbook\versions\3.2.2\lib\output\getModifiers.js:56:33
    at C:\Users\Administrator\.gitbook\versions\3.2.2\lib\output\modifiers\highlightCode.js:47:24
    at C:\Users\Administrator\.gitbook\versions\3.2.2\lib\output\modifiers\editHTMLElement.js:11:16
    at C:\Users\Administrator\.gitbook\versions\3.2.2\lib\utils\promise.js:36:16 code: 'MODULE_NOT_FOUND' }
Failed to load prism syntax: javasrcipt
{ Error: Cannot find module 'prismjs/components/prism-javasrcipt.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.code (f:\note\gitbook\vue-note\node_modules\gitbook-plugin-prism\index.js:64:11)
    at Record.TemplateBlock.applyBlock (C:\Users\Administrator\.gitbook\versions\3.2.2\lib\models\templateBlock.js:205:23)
    at C:\Users\Administrator\.gitbook\versions\3.2.2\lib\output\getModifiers.js:56:33
    at C:\Users\Administrator\.gitbook\versions\3.2.2\lib\output\modifiers\highlightCode.js:47:24
    at C:\Users\Administrator\.gitbook\versions\3.2.2\lib\output\modifiers\editHTMLElement.js:11:16
    at C:\Users\Administrator\.gitbook\versions\3.2.2\lib\utils\promise.js:36:16 code: 'MODULE_NOT_FOUND' }
info: >> generation finished with success in 9.4s !

Starting server ...
Serving book on http://localhost:4000

Failed to load prism syntax: gotemplate

{ Error: Cannot find module 'prismjs/components/prism-gotemplate.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:649:15)
    at Function.Module._load (internal/modules/cjs/loader.js:575:25)
    at Module.require (internal/modules/cjs/loader.js:705:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at requireSyntax (/Users/yemeng1/Documents/codes/go/src/golang-ship/runtime/git/avatar-mpaas/node_modules/gitbook-plugin-prism/index.js:31:3)
    at Object.code (/Users/yemeng1/Documents/codes/go/src/golang-ship/runtime/git/avatar-mpaas/node_modules/gitbook-plugin-prism/index.js:103:11)
    at Record.TemplateBlock.applyBlock (/Users/yemeng1/.gitbook/versions/3.2.3/lib/models/templateBlock.js:205:23)
    at /Users/yemeng1/.gitbook/versions/3.2.3/lib/output/getModifiers.js:56:33
    at /Users/yemeng1/.gitbook/versions/3.2.3/lib/output/modifiers/highlightCode.js:47:24
    at /Users/yemeng1/.gitbook/versions/3.2.3/lib/output/modifiers/editHTMLElement.js:11:16 code: 'MODULE_NOT_FOUND' }

not support go keyword, https://prismjs.com/#supported-languages

Ignore certain languages from being parsed by Prism

There are certain gitbook plugins that uses the three back-ticks to denote the code to be rendered.
See mermaid-full usage
And prism gives a warning like:

Failed to load prism syntax: graph
{ Error: Cannot find module 'prismjs/components/prism-graph.js' ...

It would be nice to have an option to ignore certain "languages" from being parsed by prism.

How to use Google Light?

I want to use Google Light

{
  "plugins": ["prism", "-highlight"]
}
"pluginsConfig": {  
  "prism": {
    "css": [
      "syntax-highlighting/assets/css/prism/prism-base16-google.light.css"
    ]
  }
}

But I get the error:

Error: Cannot find module 'syntax-highlighting/assets/css/prism/prism-base16-google.light.css'

Error: HonKit doesn't satisfy the requirements of this plugin: gitbook-plugin-prism require <5.0.0

Note
I understand that this plugin was create for GitBook, so if there is no room for discussion, please close

I'm using this plugin in HonKit forked from GitBook.
HonKit recently released v4.0.0 and this plugin does not work with the latest HonKit

Honkit requires a gitbook or honkit description in the engines description, with the gitbook definition taking precedence

https://github.com/honkit/honkit/blob/32e906fc392accc23940e99e284efea005398544/packages/honkit/src/plugins/validatePlugin.ts#L18-L19

The engines definition of gitbook-plugin-prism is not intended for use with v4.0.0, so you will get an error if you try to use this plugin with Honkit

"engines": {
"gitbook": ">=2.4.1 <4.0.0"
},

% node -v
v18.4.0
% honkit -V
4.0.0
% honkit build
...
Error: HonKit doesn't satisfy the requirements of this plugin: gitbook-plugin-prism require <5.0.0
    at validatePlugin (/path-to-honkit/node_modules/honkit/lib/plugins/validatePlugin.js:29:41)
    at /path-to-honkit/node_modules/honkit/lib/plugins/loadPlugin.js:81:56
    at _fulfilled (/path-to-honkit/node_modules/q/q.js:854:54)
    at /path-to-honkit/node_modules/q/q.js:883:30
    at Promise.promise.promiseDispatch (/path-to-honkit/node_modules/q/q.js:816:13)
    at /path-to-honkit/node_modules/q/q.js:570:49
    at runSingle (/path-to-honkit/node_modules/q/q.js:137:13)
    at flush (/path-to-honkit/node_modules/q/q.js:125:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

I'm considering the following options. I would like to hear opinions.

  • Remove <4.0.0 from the engine definition
  • Fork this repository and create a new honkit-plugin-prism.

Please let me know if there is a better way other than the above.
I'm prepared to create a pull request to resolve this issue.

Prism's line numbers plugin

Hello everybody!

I would like to know if it's possible to show line numbers in code blocks. I know that Prism has a line numbers plugin, and I'm wondering how to enable it.

Thanks!

Error: Cannot find module 'prismjs/components/prism-text.js'

I have installed this module,why? please give me a hand.

info: loading plugin "theme-default"... OK
info: found 110 pages
info: found 361 asset files
warn: "options" property is deprecated, use config.get(key) instead
warn: "options.generator" property is deprecated, use "output.name" instead
warn: "this.generator" property is deprecated, use "this.output.name" instead
warn: "navigation" property is deprecated
warn: "book" property is deprecated, use "this" directly instead
Failed to load prism syntax: text
{ Error: Cannot find module 'prismjs/components/prism-text.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at requireSyntax (E:\sdkDOC\tianmu-doc\node_modules\gitbook-plugin-prism\index.js:31:3)
    at Object.code (E:\sdkDOC\tianmu-doc\node_modules\gitbook-plugin-prism\index.js:103:11)
    at Record.TemplateBlock.applyBlock (C:\Users\Felix\.gitbook\versions\3.2.3\lib\models\templateBlock.js:205:23)
    at C:\Users\Felix\.gitbook\versions\3.2.3\lib\output\getModifiers.js:56:33
    at C:\Users\Felix\.gitbook\versions\3.2.3\lib\output\modifiers\highlightCode.js:47:24
    at C:\Users\Felix\.gitbook\versions\3.2.3\lib\output\modifiers\editHTMLElement.js:11:16 code: 'MODULE_NOT_FOUND' }
Failed to load prism syntax: text
{ Error: Cannot find module 'prismjs/components/prism-text.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at requireSyntax (E:\sdkDOC\tianmu-doc\node_modules\gitbook-plugin-prism\index.js:31:3)
    at Object.code (E:\sdkDOC\tianmu-doc\node_modules\gitbook-plugin-prism\index.js:103:11)
    at Record.TemplateBlock.applyBlock (C:\Users\Felix\.gitbook\versions\3.2.3\lib\models\templateBlock.js:205:23)
    at C:\Users\Felix\.gitbook\versions\3.2.3\lib\output\getModifiers.js:56:33
    at C:\Users\Felix\.gitbook\versions\3.2.3\lib\output\modifiers\highlightCode.js:47:24
    at C:\Users\Felix\.gitbook\versions\3.2.3\lib\output\modifiers\editHTMLElement.js:11:16 code: 'MODULE_NOT_FOUND' }
info: >> generation finished with success in 21.2s !

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.