Marpit

Parse Marpit Markdown and render to the slide HTML/CSS.

Constructor

new Marpit(optsopt)

Create a Marpit instance.

Parameters:
NameTypeAttributesDescription
optsObject<optional>
Properties
NameTypeAttributesDefaultDescription
anchorboolean | Marpit~AnchorCallback<optional>
true

Set the page number as anchor of each slides (id attribute). You can customize the anchor text by defining a custom callback function.

containerfalse | Element | Array.<Element><optional>
module:element.marpitContainer

Container element(s) wrapping whole slide deck.

cssContainerQueryboolean | string | Array.<string><optional>
false

Set whether to enable CSS container query (@container). By setting the string or string array, you can specify the container name(s) for the CSS container.

headingDividerfalse | number | Array.<number><optional>
false

Start a new slide page at before of headings. it would apply to headings whose larger than or equal to the specified level if a number is given, or ONLY specified levels if a number array.

langstring<optional>

Set the default lang attribute of each slide. It can override by lang global directive in the Markdown.

looseYAMLboolean<optional>
false

Allow loose YAML parsing in built-in directives, and custom directives defined in current instance.

markdownMarkdownIt | string | Object | Array<optional>

An instance of markdown-it or its constructor option(s) for wrapping. Marpit will create its instance based on CommonMark when omitted.

printableboolean<optional>
true

Make style printable to PDF.

slideContainerfalse | Element | Array.<Element><optional>

Container element(s) wrapping each slide sections.

inlineSVGboolean | Marpit~InlineSVGOptions<optional>
false

Wrap each slide sections by inline SVG. (Experimental)

Members

(readonly) customDirectives :Object

Definitions of the custom directive.

It has the assignable global and local object. They have consisted of the directive name as a key, and parser function as a value. The parser should return the validated object for updating meta of markdown-it token.

Type:
  • Object

markdown :MarkdownIt

Type:
  • MarkdownIt

(readonly) options :Object

The current options for this instance.

This property is read-only and marked as immutable. You cannot change the value of options after creating instance.

Type:
  • Object

themeSet :ThemeSet

Methods

render(markdown, envopt) → {Marpit~RenderResult}

Render Markdown into HTML and CSS string.

Parameters:
NameTypeAttributesDefaultDescription
markdownstring

A Markdown string.

envObject<optional>
{}

Environment object for passing to markdown-it.

Properties
NameTypeAttributesDefaultDescription
htmlAsArrayboolean<optional>
false

Output rendered HTML as array per slide.

Returns:

An object of rendering result.

Type: 
Marpit~RenderResult

use(plugin, …params) → {Marpit}

Load the specified markdown-it plugin with given parameters.

Parameters:
NameTypeAttributesDescription
pluginfunction

markdown-it plugin.

params*<repeatable>

Params to pass into plugin.

Returns:

The called Marpit instance for chainable.

Type: 
Marpit

Type Definitions

AnchorCallback(index) → {string}

Convert slide page index into anchor string.

Parameters:
NameTypeDescription
indexnumber

Slide page index, beginning from zero.

Returns:

The text of anchor for id attribute, without prefix #.

Type: 
string

InlineSVGOptions

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
enabledboolean<optional>
true

Whether inline SVG mode is enabled.

backdropSelectorboolean<optional>
true

Whether ::backdrop selector support is enabled. If enabled, the ::backdrop CSS selector will match to the SVG container element.

RenderResult

Type:
  • Object
Properties
NameTypeDescription
htmlstring | Array.<string>

Rendered HTML.

cssstring

Rendered CSS.

commentsArray.<Array.<string>>

Parsed HTML comments per slide pages, excepted YAML for directives. It would be useful for presenter notes.