Expand description
interface MarkdownIt {
inline: ParserInline;
block: ParserBlock;
core: ParserCore;
renderer: Renderer;
linkify: LinkifyIt;
validateLink(url: string): boolean;
normalizeLink(url: string): string;
normalizeLinkText(url: string): string;
utils: md.utils;
helpers: md.helpers;
options: Required<MarkdownItOptions>;
set(options: MarkdownItOptions): this;
configure(
presets: MarkdownItPreset | "default" | "zero" | "commonmark",
): this;
enable(list: string | string[], ignoreInvalid?: boolean): this;
disable(list: string | string[], ignoreInvalid?: boolean): this;
use<Params extends unknown[]>(
plugin: (md: this, ...params: Params) => void,
...params: Params,
): this;
parse(src: string, env: Env): Token[];
render(src: string, env?: Env): string;
parseInline(src: string, env: Env): Token[];
renderInline(src: string, env?: Env): string;
}
Properties§
inline: ParserInline = ...
Instance of ParserInline. You may need it to add new rules when writing plugins. For simple rules control use MarkdownIt.disable and MarkdownIt.enable.
block: ParserBlock = ...
Instance of ParserBlock. You may need it to add new rules when writing plugins. For simple rules control use MarkdownIt.disable and MarkdownIt.enable.
core: ParserCore = ...
Instance of ParserCore chain executor. You may need it to add new rules when writing plugins. For simple rules control use MarkdownIt.disable and MarkdownIt.enable.
renderer: Renderer = ...
Instance of Renderer. Use it to modify output look. Or to add rendering rules for new token types, generated by plugins.
See Renderer docs and source code.
linkify: LinkifyIt = ...
linkify-it instance. Used by linkify rule.
utils: md.utils = utils
Assorted utility functions, useful to write plugins. See details here.
helpers: md.helpers = ...
Link components parser functions, useful to write plugins. See details here.
options: Required<MarkdownItOptions>
Methods§
Source§
validateLink(url: string): boolean
validateLink(url: string): boolean
Link validation function. CommonMark allows too much in links. By default
we disable javascript:, vbscript:, file: schemas, and almost all data:... schemas
except some embedded image types.
You can change this behaviour:
Source§
normalizeLink(url: string): string
normalizeLink(url: string): string
Function used to encode link url to a machine-readable format, which includes url-encoding, punycode, etc.
Source§
normalizeLinkText(url: string): string
normalizeLinkText(url: string): string
Function used to decode link url to a human-readable format`
Source§
set(options: MarkdownItOptions): this
set(options: MarkdownItOptions): this
Set parser options (in the same format as in constructor). Probably, you will never need it, but you can change options after constructor call.
Note: To achieve the best possible performance, don't modify a
markdown-it instance options on the fly. If you need multiple configurations
it's best to create multiple instances and initialize each with separate
config.
Source§
configure(presets: MarkdownItPreset | "default" | "zero" | "commonmark"): this
configure(presets: MarkdownItPreset | "default" | "zero" | "commonmark"): this
Batch load of all options and compenent settings. This is internal method, and you probably will not need it. But if you will - see available presets and data structure here
We strongly recommend to use presets instead of direct config loads. That will give better compatibility with next versions.
Source§
enable(list: string | string[], ignoreInvalid?: boolean): this
enable(list: string | string[], ignoreInvalid?: boolean): this
Enable list or rules. It will automatically find appropriate components,
containing rules with given names. If rule not found, and ignoreInvalid
not set - throws exception.
Source§
disable(list: string | string[], ignoreInvalid?: boolean): this
disable(list: string | string[], ignoreInvalid?: boolean): this
The same as MarkdownIt.enable, but turn specified rules off.
Source§
use<Params extends unknown[]>(
plugin: (md: this, ...params: Params) => void,
...params: Params,
): this
use<Params extends unknown[]>(
plugin: (md: this, ...params: Params) => void,
...params: Params,
): this
Load specified plugin with given params into current parser instance.
It's just a sugar to call plugin(md, params) with curring.
Source§
parse(src: string, env: Env): Token[]
parse(src: string, env: Env): Token[]
Parse input string and return list of block tokens (special token type "inline" will contain list of inline tokens). You should not call this method directly, until you write custom renderer (for example, to produce AST).
env is used to pass data between "distributed" rules and return additional
metadata like reference info, needed for the renderer. It also can be used to
inject data in specific cases. Usually, you will be ok to pass {},
and then pass updated object to renderer.
Source§
render(src: string, env?: Env): string
render(src: string, env?: Env): string
Render markdown string into html. It does all magic for you :).
env can be used to inject additional metadata ({} by default).
But you will not need it with high probability. See also comment
in MarkdownIt.parse.
Source§
parseInline(src: string, env: Env): Token[]
parseInline(src: string, env: Env): Token[]
The same as MarkdownIt.parse but skip all block rules. It returns
the block tokens list with the single inline element, containing parsed
inline tokens in children property. Also updates env object.
Source§
renderInline(src: string, env?: Env): string
renderInline(src: string, env?: Env): string
Similar to MarkdownIt.render but for single paragraph content.
Result will NOT be wrapped into <p> tags.
Parses Markdown into tokens and renders them to HTML.