javascript - How to use data-manual in prism.js -
i'm using prism.js syntax highlighter website, want items not te rendered, operators , punctuation.
now, manual of prism.js states:
if want prevent elements being automatically highlighted, can use attribute data-manual on element used prism , use api. example:
<script src="prism.js" data-manual></script>
but that's it. no further examples. link api shows javascript functions, nothing further on data-manual
. als if google site:prismjs.com "data-manual"
, no helpful occurances show up.
can me on how illusive data-manual
-attribute needs used?
i didn't understand how use data-manual documentation--i had @ source. use 'data-manual' when want directly call prism's api adding syntax highlighting. checkout api reference.
if don't set data-manual, prism set timeout or listener call highlightall (here relevant source). highlight every element matched following selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
if want finer-grained control of timing, or maybe don't want prism adding classes, add data-manual script tag script contains prismjs, call highlight yourself. here's basic es6 example of how might use prism in manual mode:
import {highlight} 'prismjs'; import 'prismjs/components/prism-python'; const pythoncode = 'mystring = "some string"'; const highlightedcode = highlight(pythoncode, prism.languages.python); const highlightedhtml = `<pre><code class="language-python">${highlightedcode}</code></pre>`; document.getelementbyid('myid').innerhtml=highlightedhtml;
Comments
Post a Comment