markdown_it.ruler module#

class Ruler

Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and [[MarkdownIt#inline]] to manage sequences of functions (rules):

  • keep rules in defined order

  • assign the name to each rule

  • enable/disable rules

  • add/replace rules

  • allow assign rules to additional named chains (in the same)

  • caching lists of active rules

You will not need use this class directly until write plugins. For simple rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and [[MarkdownIt.use]].

class markdown_it.ruler.Rule(name: 'str', enabled: 'bool', fn: 'RuleFunc', alt: 'list[str]')[source]#

Bases: object

alt: list[str]#
enabled: bool#
fn: RuleFunc#
name: str#
class markdown_it.ruler.Ruler[source]#

Bases: object

after(afterName: str, ruleName: str, fn: collections.abc.Callable, options=None)[source]#

Add new rule to chain after one with given name.

Parameters
  • afterName – new rule will be added after this one.

  • ruleName – new rule will be added after this one.

  • fn – new rule function.

  • options – new rule options (not mandatory).

Raises

KeyError if name not found

at(ruleName: str, fn: collections.abc.Callable, options=None)[source]#

Replace rule by name with new function & options.

Parameters
  • ruleName – rule name to replace.

  • fn – new rule function.

  • options – new rule options (not mandatory).

Raises

KeyError if name not found

before(beforeName: str, ruleName: str, fn: collections.abc.Callable, options=None)[source]#

Add new rule to chain before one with given name.

Parameters
  • beforeName – new rule will be added before this one.

  • ruleName – new rule will be added before this one.

  • fn – new rule function.

  • options – new rule options (not mandatory).

Raises

KeyError if name not found

disable(names: str | Iterable[str], ignoreInvalid: bool = False)[source]#

Disable rules with given names.

Parameters
  • names – name or list of rule names to enable.

  • ignoreInvalid – ignore errors when rule not found

Raises

KeyError if name not found and not ignoreInvalid

Returns

list of found rule names

enable(names: str | Iterable[str], ignoreInvalid: bool = False)[source]#

Enable rules with given names.

Parameters
  • names – name or list of rule names to enable.

  • ignoreInvalid – ignore errors when rule not found

Raises

KeyError if name not found and not ignoreInvalid

Returns

list of found rule names

enableOnly(names: str | Iterable[str], ignoreInvalid: bool = False)[source]#

Enable rules with given names, and disable everything else.

Parameters
  • names – name or list of rule names to enable.

  • ignoreInvalid – ignore errors when rule not found

Raises

KeyError if name not found and not ignoreInvalid

Returns

list of found rule names

getRules(chainName: str) list[RuleFunc][source]#

Return array of active functions (rules) for given chain name. It analyzes rules configuration, compiles caches if not exists and returns result.

Default chain name is ‘’ (empty string). It can’t be skipped. That’s done intentionally, to keep signature monomorphic for high speed.

get_active_rules() list[str][source]#

Return the active rule names.

get_all_rules() list[str][source]#

Return all available rule names.

push(ruleName: str, fn: collections.abc.Callable, options=None)[source]#

Push new rule to the end of chain.

Parameters
  • ruleName – new rule will be added to the end of chain.

  • fn – new rule function.

  • options – new rule options (not mandatory).

class markdown_it.ruler.StateBase(src: str, md: MarkdownIt, env: MutableMapping)[source]#

Bases: object

property src: str#
srcCharCode: tuple[int, ...]#