Enable HTML tags in source.
Use '/' to close single tags (<br />).
Convert '\n' in paragraphs into <br>.
CSS language prefix for fenced blocks, used by external syntax highlighters.
Autoconvert URL-like text to links.
Enable language-neutral replacements and quotes beautification.
See the replacement rules for the full list.
Double + single quotes replacement pairs, when typographer is enabled and smartquotes are on. Can be either a string or an array.
For example, use '«»„“' for Russian, '„“‚‘' for German, and
['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
Highlighter function. Should return escaped HTML, or an empty string if
the source string was not changed and should be escaped externally.
If the result starts with <pre, the internal wrapper is skipped.
The highlighter is called by the default fence renderer rule. If needed,
you can replace that renderer rule completely; see the
renderer source.
import MarkdownIt from 'markdown-it'
import hljs from 'highlight.js' // https://highlightjs.org
const md = new MarkdownIt({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(str, { language: lang }).value
} catch (__) {}
}
return '' // use external default escaping
}
});
Or with full wrapper override (if you need assign class to <pre> or <code>):
import MarkdownIt from 'markdown-it'
import hljs from 'highlight.js' // https://highlightjs.org
const md = new MarkdownIt({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return `<pre><code class="hljs">${hljs.highlight(str,
{ language: lang, ignoreIllegals: true }).value}</code></pre>`
} catch (__) {}
}
return `<pre><code class="hljs">${md.utils.escapeHtml(str)}</code></pre>`
}
});
Internal protection against excessive recursion.
Options controlling Markdown parsing and rendering.