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)

  • cacheing 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: Callable, alt: List[str])[源代码]

基类:object

alt: List[str]
enabled: bool
fn: Callable
name: str
class markdown_it.ruler.Ruler[源代码]

基类:object

after(afterName: str, ruleName: str, fn: Callable, options=None)[源代码]

Add new rule to chain after one with given name.

参数
  • 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: Callable, options=None)[源代码]

Replace rule by name with new function & options.

参数
  • 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: Callable, options=None)[源代码]

Add new rule to chain before one with given name.

参数
  • 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: Union[str, Iterable[str]], ignoreInvalid: bool = False)[源代码]

Disable rules with given names.

参数
  • 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

返回

list of found rule names

enable(names: Union[str, Iterable[str]], ignoreInvalid: bool = False)[源代码]

Enable rules with given names.

参数
  • 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

返回

list of found rule names

enableOnly(names: Union[str, Iterable[str]], ignoreInvalid: bool = False)[源代码]

Enable rules with given names, and disable everything else.

参数
  • 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

返回

list of found rule names

getRules(chainName: str) List[Callable][源代码]

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][源代码]

Return the active rule names.

get_all_rules() List[str][源代码]

Return all available rule names.

push(ruleName: str, fn: Callable, options=None)[源代码]

Push new rule to the end of chain.

参数
  • 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)[源代码]

基类:object

property src: str
srcCharCode: Tuple[int, ...]