docsify icon indicating copy to clipboard operation
docsify copied to clipboard

Prismjs configuration

Open automada opened this issue 8 years ago • 7 comments

Hi, nice project! Is there any easy way of changing themes and adding plugins for prism.js? Adding the js-files alone doesn't seem to have any effect.

automada avatar Jan 26 '18 20:01 automada

https://docsify.js.org/#/language-highlight

QingWei-Li avatar Jan 27 '18 02:01 QingWei-Li

Thanks for the quick reply, but I was thinking more about the theming e.g. Solarized, and plugins, like line numbers. I tried to add the css+js as the prism docs describe, and I see the plugin is registered in prism in the console, but nothing happens.

automada avatar Jan 27 '18 17:01 automada

I just call the Prism.highlight() API to highlight the code. I read the Prism source code, the plugins can not work in such the way.

QingWei-Li avatar Jan 28 '18 13:01 QingWei-Li

Thanks for clearing that up, still a really nice project :)

automada avatar Jan 28 '18 13:01 automada

I have the same question and steps to achieve it are pretty straightforward. You have all prism available themes here: https://unpkg.com/[email protected]/themes/

So in your HTML need to add this line after link vue.css styles, to override with okaidia theme:

<link rel="stylesheet" href="//unpkg.com/prismjs/themes/prism-okaidia.css">

Finally, to polish what you get, there are some styles at vue.css that need to change, básically this ones:

.markdown-section code,
.markdown-section pre,
.markdown-section pre > code {
    color: #eee; /* default color for elements not styled by prism theme */
    background-color: #353544; /* dark background, because vue.css modify it */
}

/* because the bgcolor change in previous css rule. font-color when using inline code tag */
.markdown-section code {
    color: #eccb84; 
}

Hope it helps :)

qmarcos avatar Aug 31 '18 11:08 qmarcos

@qmarcos Thank you so much !

cgatian avatar Sep 26 '18 12:09 cgatian

@qmarcos thanks for saving my time 🙏

JeffShomali avatar Jun 25 '20 06:06 JeffShomali