Plugins are the most easy way to distribute an extension for remarkable.
Plugins are expected to be loaded using md.use(plugin[, opts])
(where md
is
your instance of Remarkable.).
Plugins are nothing more than a function taking two arguments:
md
: the Remarkable instance on which the plugin needs to be activatedoptions
: the set of options that has been provided tomd.use
Plugins are then expected to add parsing and rendering rules and carry on appropriate modifications on the remarkable instance.
It's as simple as that.
Remarkable converts markdown to HTML in two steps:
- Parsing markdown raw text to a list of tokens
- Rendering the list of tokens to actual HTML code.
Parsing rules are divided into three differents kind of rules (core, block and inline).
To add a parsing rule, you will need to get the relevant parser for your rule
(core
, block
or inline
) and insert your rule at the appropriate position
in the ruler
.
For example, to add a new inline for strike-through, you'd need to do:
md.inline.ruler.push("strike-through", strikeThroughInlineRule, { strokesCount: 2 });
where strikeThroughInlineRule
is your parsing rule for
strike-through.
To add a rendering rule, you need to follow exactly the same process, but using
the ruler md.renderer.rules
.
Rulers provide four main methods to manage their rules:
before(beforeName, ruleName, fn, options)
: inserts a new rule before the rulebeforeName
.after(afterName, ruleName, fn, options)
: inserts a new rule after the ruleafterName
.push(ruleName, fn, options)
: inserts a new rule at the end of the rule list.at(ruleName, fn, options)
: replace the ruleruleName
with a new rule.