Constructor#
new ThemeSet(optsopt)#
Create a ThemeSet instance.
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts | Object | <optional> | Properties
|
- Source
Members#
cssNesting :boolean#
A boolean value indicating whether the theme set is enabling CSS nesting or not.
- boolean
- Source
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
).
- Theme |
undefined
- Source
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']
- Object
- Source
(readonly) size :number#
Return the number of themes.
- number
- Source
Methods#
add(css) → {Theme}#
Add theme CSS from string.
Name | Type | Description |
---|---|---|
css | string | The theme CSS string. |
- Source
Will throw an error if the theme name is not specified by @theme
metadata.
addTheme(theme)#
Add theme instance.
Name | Type | Description |
---|---|---|
theme | Theme | The theme instance. |
- Source
Will throw an error if the theme name is not specified.
clear()#
Removes all themes from a themeSet object.
- Source
delete(name) → {boolean}#
Remove a specific named theme from a themeSet object.
Name | Type | Description |
---|---|---|
name | string | The theme name to delete. |
- Source
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.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | The theme name to get. | ||
fallback | boolean | <optional> | false | If true, return instance's default theme or scaffold theme when specified theme cannot find. |
- Source
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.
Name | Type | Description |
---|---|---|
theme | string | | The theme name or instance. |
meta | string | The meta name to get. |
- Source
- 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
.
Name | Type | Description |
---|---|---|
theme | string | | The theme name or instance. |
prop | string | The property name to get. |
- Source
- Type:
- *
has(name) → {boolean}#
Returns a boolean indicating whether a specific named theme exists or not.
Name | Type | Description |
---|---|---|
name | string | The theme name. |
- Source
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.
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name | string | The theme name. It will use the instance's default theme or scaffold theme when a specific named theme does not exist. | |||||||||||||||||||||||||||||
opts | Object | <optional> | The option object passed by Marpit#render. Properties
|
- Source
The converted CSS string.
- Type:
- string
themes() → {Iterator.<Theme>}#
Returns a Iterator
object that contains registered themes to current instance.
- Source
- Type:
- Iterator.<Theme>