About the Library
Code highlighting is handled by the Prism library. Prism is a lightweight, robust, elegant syntax highlighting library with huge language coverage and many themes to choose from.
Use Prism to highlight blocks of code in your site.
About the Library
Code highlighting is handled by the Prism library. Prism is a lightweight, robust, elegant syntax highlighting library with huge language coverage and many themes to choose from.
Initializing
The demo pages already include the following code. These steps are only necessary if you are building a page from scratch. Remove these references if you are not using this plugin to improve page load times.
Copy the script tag below and paste in the foot of your page. Add this where you see the other library scripts. This line should be inserted after jquery.js
and before theme.js
.
<!-- Prism (displays formatted code boxes) -->
<script type="text/javascript" src="assets/js/prism.js"></script>
Alternatively you may wish to load this resource from a CDN to potentially improve page load times.
<!-- Prism (displays formatted code boxes) -->
<script type="text/javascript" src="https://unpkg.com/prismjs@^1.21.0/prism.js"></script>
index.js
js/mrare/index.js
. This ensures that the initializer code is included in the theme.js
bundle.import './prism';
components.scss
scss/custom/components.scss
:@import "components/optional/prism";
Basic Usage
NOTE: Special characters must be written as character entity references in order to appear in your code box.
Add code to your pages using the following syntax:
<pre>
<code class="language-html">
<h2 data-countdown-date="2019/08/05"></h2>
</code>
</pre>
Prism will automatically format and highlight the code on page load.
You may use this online tool to do the conversion.
See this reference at Wikipedia for available HTML entity references.
Themes
You may include other colour themes for Prism by including them in theme.css
.
scss/custom/components/plugins
folder.scss/custom/components/optional/prism.scss
and add the following import directive after the prism.css
import:@import "CSS:../../components/plugins/prism-okaidia.css";
Themes can be found at the Prism download page or through a quick search.