Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I cannot get a colored code with docsify?

Tags:

docsify

I am using docsify to build a documentation for my API. However when I insert code block (especially json) the code is written in black.

I don't know how to change it.

Any suggestion ?

like image 217
John doe Avatar asked Sep 04 '26 17:09

John doe


2 Answers

Docsify uses Prism for syntax highlighting as explained in the Documentation.

To add support for a specific language you need to add the matching grammar file as so :

<!-- Loading Docsify -->
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script>
<!-- Adding json syntax highlighting -->
<script src="//cdn.jsdelivr.net/npm/[email protected]/components/prism-json.min.js"></script>

If you want to browse the list of grammar files available you can browse them here : PrismJS on Github

like image 83
Demian Vnh Avatar answered Sep 07 '26 09:09

Demian Vnh


What worked for me, at least for PHP, was to make sure the language files were included before the main prism library.

  <script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
  <script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-php.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/[email protected]/prism.min.js"></script>
like image 29
Dustin Butler Avatar answered Sep 07 '26 10:09

Dustin Butler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!