Constructor options
You can customize a behavior of Marp parser by passing an options object to the constructor. You can also pass together with Marpit constructor options.
[!NOTE]
Marpit's markdown option is accepted only object options because of always using CommonMark.
const marp = new Marp({
html: true,
emoji: {
shortcode: true,
unicode: false,
twemoji: {
base: '/resources/twemoji/',
},
},
math: 'katex',
minifyCSS: true,
script: {
source: 'cdn',
nonce: 'xxxxxxxxxxxxxxx',
},
slug: false,
looseYAML: false,
markdown: {
breaks: false,
},
})
html: boolean | object
Setting whether to render raw HTML in Markdown. It's an alias to markdown.html (markdown-it option) but has additional feature about HTML allowlist.
- (default): Use Marp's default allowlist.
true: The all HTML will be allowed.
false: All HTML except supported in Marpit Markdown will be disallowed.
By passing object, you can set the allowlist to specify allowed tags and attributes.
{
a: ['href', 'target'],
br: [],
}
{
img: {
src: (value) => (value.startsWith('https://') ? value : '')
}
}
By default, Marp Core allows known HTML elements and attributes that are considered as safe. That is defined as a readonly html member in Marp class. See the full default allowlist in the source code.
[!NOTE]
Whatever any option is selected, <!-- HTML comment --> and <style> tags are always parsed by Marpit for directives / tweaking style.
emoji: object
Setting about emoji conversions.
shortcode: boolean | "twemoji"
- By setting
false, it does not convert any emoji shortcodes.
- By setting
true, it converts emoji shortcodes into Unicode emoji. :dog: → 
- By setting
"twemoji" string, it converts into twemoji vector image. :dog: →
(default)
unicode: boolean | "twemoji"
- It can convert Unicode emoji into twemoji when setting
"twemoji".
→
(default)
- If you not want this aggressive conversion, please set
false.
For developers: When you setting unicode option as true, Markdown parser will convert Unicode emoji into tokens internally. The rendering result is same as in false.
math: boolean | "mathjax" | "katex" | object
Enable or disable math typesetting syntax and math global directive.
You can choose the default library for math by passing "mathjax" (default) or "katex", and modify more settings by passing an object of sub-options.
lib: "mathjax" | "katex"
- Choose the default library for math typesetting. (
mathjax by default)
katexFontPath: string | false
- By default, Marp Core will use online web-font resources through jsDelivr CDN. You have to set path to fonts directory if you want to use local resources. If you set
false, we will not manipulate the path (Use KaTeX's original path: fonts/KaTeX_***-***.woff2).
minifyCSS: boolean
Enable or disable minification for rendered CSS. true by default.
script: boolean | object
Setting about an injected helper script for the browser context. This script is necessary for applying WebKit polyfill and rendering auto-scaled elements correctly.
true (default): Inject the inline helper script into after the last of slides.
false: Don't inject helper script. Developer must execute a helper script manually, exported in @marp-team/marp-core/browser. Requires bundler such as webpack. It's suitable to the fully-controlled tool such as Marp Web.
You can control details of behavior by passing object.
source: string - Choose the kind of script.
inline: Inject the inline script. It would work correctly also in the environment that there is not network. (default)
cdn: Inject script referred through jsDelivr CDN. It's better choice on the restricted environment by CSP.
slug: boolean | function | object
Configure slugification for headings. By default, Marp Core tries to make the slug by the similar way to GitHub. It should be compatible with Markdown Language Server.
true (default): Assign auto-generated id attribute from the contents of <h1>-<h6> headings.
false: Disable auto-assigning slug to headings.
function: Set the custom slugifier function, that takes one argument: the content of the heading. It must return a generated slug string.
You can control details of behavior by passing object.
-
slugifier: function - Set the custom slugifier function.
-
postSlugify: function - Set the post-process function after generated a slug. The function takes 2 arguments, the string of generated slug and the index of the same slug, and must return a string for assigning to id attribute of the heading.
By default, Marp Core applies the post-process to avoid assigning duplicated ids in the document: (slug, index) => (index > 0 ? `${slug}-${index}` : slug)
Assigning the custom post-process function is also helpful to append the custom prefix and suffix to the generated slug: (slug, i) => `prefix:${slug}:${i}`
[!NOTE]
Take care not to confuse Marp Core's slug option and Marpit's anchor option. slug is for the Markdown headings, and anchor is for the slide elements.
Marp class is extended from Marpit class so you can customize both options in the constructor. To fully disable auto-generated id attribute, set both options as false. (This is important to avoid breaking your Web application by user's Markdown contents)
Contributing
Are you interested in contributing? Please see CONTRIBUTING.md and the common contributing guideline for Marp team.
Author
Managed by @marp-team.
License
This package releases under the MIT License.