ThemeSet

Marpit theme set class.

Constructor

new ThemeSet(optsopt)

Create a ThemeSet instance.

Parameters:
NameTypeAttributesDescription
optsObject<optional>
Properties
NameTypeAttributesDefaultDescription
cssNestingboolean<optional>
true

Enable CSS nesting support.

Members

cssNesting :boolean

A boolean value indicating whether the theme set is enabling CSS nesting or not.

Type:
  • boolean

default :Theme|undefined

An instance of default theme.

While running ThemeSet#pack, ThemeSet will use this theme when the definition of theme directive or the theme with specified name is not found.

By default, Marpit does not provide default theme (undefined).

Type:

metaType :Object

The default type settings for theme metadata added by ThemeSet#add.

A key of object is the name of metadata and a value is the type which of String and Array. You have to set Array if the theme allows multi-time definitions in same meta key.

/**
 * @theme example
 * @foo Single value
 * @foo allows only one string
 * @bar Multiple value 1
 * @bar Multiple value 2
 * @bar Multiple value 3
 * ...
const themeSet = new ThemeSet()

themeSet.metaType = {
  foo: String,
  bar: Array,
}

themeSet.add(css)

console.log(themeSet.getThemeMeta('example', 'foo'))
// => 'allows only one string'

console.log(themeSet.getThemeMeta('example', 'bar'))
// => ['Multiple value 1', 'Multiple value 2', 'Multiple value 3']
Type:
  • Object

(readonly) size :number

Return the number of themes.

Type:
  • number

Methods

add(css) → {Theme}

Add theme CSS from string.

Parameters:
NameTypeDescription
cssstring

The theme CSS string.

Throws:

Will throw an error if the theme name is not specified by @theme metadata.

Returns:

A created Theme instance.

Type: 
Theme

addTheme(theme)

Add theme instance.

Parameters:
NameTypeDescription
themeTheme

The theme instance.

Throws:

Will throw an error if the theme name is not specified.

clear()

Removes all themes from a themeSet object.

delete(name) → {boolean}

Remove a specific named theme from a themeSet object.

Parameters:
NameTypeDescription
namestring

The theme name to delete.

Returns:

Returns true if a theme in current ThemeSet existed and has been removed, or false if the theme does not exist.

Type: 
boolean

get(name, fallbackopt) → {Theme|undefined}

Returns a specific named theme.

Parameters:
NameTypeAttributesDefaultDescription
namestring

The theme name to get.

fallbackboolean<optional>
false

If true, return instance's default theme or scaffold theme when specified theme cannot find.

Returns:

Returns specified or fallbacked theme, or undefined if fallback is false and the specified theme has not existed.

Type: 
Theme | undefined

getThemeMeta(theme, meta) → {string|Array.<string>|undefined}

Returns value(s) of specified metadata from a theme. It considers @import and @import-theme rules in getting meta value. On the other hand, the default theme specified by the instance is not considered.

To support metadata with array type, it will merge into a flatten array when the all of got valid values that includes imported themes are array.

Parameters:
NameTypeDescription
themestring | Theme

The theme name or instance.

metastring

The meta name to get.

Returns:
Type: 
string | Array.<string> | undefined

getThemeProp(theme, prop) → {*}

Returns the value of specified property name from a theme. It considers @import and @import-theme rules in getting value.

It will fallback the reference object into the instance's default theme or scaffold theme when the specified theme is undefined.

Parameters:
NameTypeDescription
themestring | Theme

The theme name or instance.

propstring

The property name to get.

Returns:
Type: 
*

has(name) → {boolean}

Returns a boolean indicating whether a specific named theme exists or not.

Parameters:
NameTypeDescription
namestring

The theme name.

Returns:

Returns true if a specific named theme exists, otherwise false.

Type: 
boolean

pack(name, optsopt) → {string}

Convert registered theme CSS into usable in the rendered markdown by Marpit#render.

This method is designed for internal use by Marpit class. Use Marpit#render instead unless there is some particular reason.

Parameters:
NameTypeAttributesDescription
namestring

The theme name. It will use the instance's default theme or scaffold theme when a specific named theme does not exist.

optsObject<optional>

The option object passed by Marpit#render.

Properties
NameTypeAttributesDescription
afterstring<optional>

A CSS string to append into after theme.

beforestring<optional>

A CSS string to prepend into before theme.

containersArray.<Element><optional>

Container elements wrapping whole slide deck.

containerQueryboolean | string | Array.<string><optional>

Enable CSS container query by setting true. You can also specify the name of container for CSS container query used by the @container at-rule in child elements.

printableboolean<optional>

Make style printable to PDF.

inlineSVGMarpit~InlineSVGOptions<optional>

Apply a hierarchy of inline SVG to CSS selector by setting true. (Experimental)

Returns:

The converted CSS string.

Type: 
string

themes() → {Iterator.<Theme>}

Returns a Iterator object that contains registered themes to current instance.

Returns:
Type: 
Iterator.<Theme>