Expand description
interface Ruler<Args extends unknown[], Result> {
__rules__: {
name: string;
enabled: boolean;
fn: (...args: Args) => Result;
alt: string[];
}[];
__cache__: Record<string, ((...args: Args) => Result)[]>
| null;
__find__(name: string): number;
__compile__(): void;
at(
name: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void;
before(
beforeName: string,
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void;
after(
afterName: string,
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void;
push(
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void;
enable(list: string | string[], ignoreInvalid?: boolean): string[];
enableOnly(list: string | string[], ignoreInvalid?: boolean): void;
disable(list: string | string[], ignoreInvalid?: boolean): string[];
getRules(chainName: string): ((...args: Args) => Result)[];
}
Properties§
__ rules __: { name: string; enabled: boolean; fn: (...args: Args) => Result; alt: string[] }[] = []
§__ cache __: Record<string, ((...args: Args) => Result)[]> | null = null
Methods§
Source§
at(
name: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void
at(
name: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void
Replace rule by name with new function & options. Throws error if name not found.
Source§
before(
beforeName: string,
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void
before(
beforeName: string,
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void
Add new rule to chain before one with given name. See also Ruler.after, Ruler.push.
Source§
after(
afterName: string,
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void
after(
afterName: string,
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void
Add new rule to chain after one with given name. See also Ruler.before, Ruler.push.
Source§
push(
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void
push(
ruleName: string,
fn: (...args: Args) => Result,
options?: { alt?: string[] },
): void
Push new rule to the end of chain. See also Ruler.before, Ruler.after.
Source§
enable(list: string | string[], ignoreInvalid?: boolean): string[]
enable(list: string | string[], ignoreInvalid?: boolean): string[]
Enable rules with given names. If any rule name not found - throw Error. Errors can be disabled by second param.
See also Ruler.disable, Ruler.enableOnly.
Source§
enableOnly(list: string | string[], ignoreInvalid?: boolean): void
enableOnly(list: string | string[], ignoreInvalid?: boolean): void
Enable rules with given names, and disable everything else. If any rule name not found - throw Error. Errors can be disabled by second param.
See also Ruler.disable, Ruler.enable.
Source§
disable(list: string | string[], ignoreInvalid?: boolean): string[]
disable(list: string | string[], ignoreInvalid?: boolean): string[]
Disable rules with given names. If any rule name not found - throw Error. Errors can be disabled by second param.
See also Ruler.enable, Ruler.enableOnly.
Source§
getRules(chainName: string): ((...args: Args) => Result)[]
getRules(chainName: string): ((...args: Args) => Result)[]
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.
Helper class, used by MarkdownIt.core, MarkdownIt.block and MarkdownIt.inline to manage sequences of functions (rules):
You will not need use this class directly until write plugins. For simple rules control use MarkdownIt.disable, MarkdownIt.enable and MarkdownIt.use.