You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The plugin will insert the necessary markup into all code blocks. Include one of Prism’s stylesheets in
your HTML to get highlighted code.
Options
The options object may contain:
Name
Description
Default
highlightInlineCode
Whether to highlight inline code.
false
plugins
Array of Prism Plugins to load. The names to use can be found here. Please note that some prism plugins (notably line-numbers) rely on the DOM being present and can thus not be used with this package (see #1).
[]
init
A function called after setting up prism. Will receive the prism instance as only argument. Useful for plugins needing further intialisation.
() => {}
defaultLanguageForUnknown
The language to use for code blocks that specify a language that Prism does not know. No default will be used if this option is undefined.
undefined
defaultLanguageForUnspecified
The language to use for code block that do not specify a language. No default will be used if this option is undefined.
undefined
defaultLanguage
Shorthand to set both defaultLanguageForUnknown and defaultLanguageForUnspecified to the same value.
undefined
Inline Code
When highlightInlineCode is set, inline code will be highlighted just like fenced code blocks are.
To specifiy the language of inline code, add {language=<your-language>} after the code segment:
`class Demo { };`{language=cpp}
This syntax is compatible with markdown-it-attrs:
The language=<x> part will be stripped, but everything else between { and } will work
with markdown-it-attrs as usual.
Usage with Webpack
If you want to use this plugin together with Webpack, you need to import all languages you intend to use:
importMarkdownItfrom'markdown-it';importprismfrom'markdown-it-prism';import"prismjs/components/prism-clike"import"prismjs/components/prism-java"functioncomponent(){constmd=newMarkdownIt();md.use(prism);constelement=document.createElement('div');element.innerHTML=md.render(`Here is some *code*:\`\`\`javapublic class Test { public void foo() {}}\`\`\``);returnelement;}document.body.appendChild(component());
Beware: Prisms languages have dependencies onto each other. You need to import the languages together with their dependencies in the
correct order.