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
- fn: Callable¶
- 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.