markdown-it - v15.0.2
    Preparing search index...

    Interface MarkdownIt

    Parses Markdown into tokens and renders them to HTML.

    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;
    }
    Index

    Instance of ParserInline. You may need it to add new rules when writing plugins. For simple rules control use MarkdownIt.disable and MarkdownIt.enable.

    Instance of ParserBlock. You may need it to add new rules when writing plugins. For simple rules control use MarkdownIt.disable and MarkdownIt.enable.

    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.

    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.

    import MarkdownIt from 'markdown-it'
    const md = new MarkdownIt()

    function myToken(tokens, idx, options, env, self) {
    //...
    return result;
    };

    md.renderer.rules['my_token'] = myToken

    linkify-it instance. Used by linkify rule.

    Assorted utility functions, useful to write plugins. See details here.

    Link components parser functions, useful to write plugins. See details here.

    • Function used to decode link url to a human-readable format`

      Parameters

      • url: string

      Returns string

    • 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.

      Parameters

      Returns this

      import MarkdownIt from 'markdown-it'

      const md = new MarkdownIt()
      .set({ html: true, breaks: true })
      .set({ typographer: true })
    • 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.

      Parameters

      Returns 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.

      Parameters

      • list: string | string[]
      • ignoreInvalid: boolean = false

      Returns this

      import MarkdownIt from 'markdown-it'

      const md = new MarkdownIt()
      .enable(['sub', 'sup'])
      .disable('smartquotes')
    • The same as MarkdownIt.enable, but turn specified rules off.

      Parameters

      • list: string | string[]
      • ignoreInvalid: boolean = false

      Returns this

    • Load specified plugin with given params into current parser instance. It's just a sugar to call plugin(md, params) with curring.

      Type Parameters

      • Params extends unknown[]

      Parameters

      • plugin: (md: this, ...params: Params) => void
      • ...params: Params

      Returns this

      import MarkdownIt from 'markdown-it'
      import iterator from 'markdown-it-for-inline'

      const md = new MarkdownIt()
      .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
      tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar')
      })
    • 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.

      Parameters

      • src: string
      • env: Env

      Returns Token[]

    • 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.

      Parameters

      • src: string
      • env: Env = {}

      Returns string

    • 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.

      Parameters

      • src: string
      • env: Env

      Returns Token[]

    • Similar to MarkdownIt.render but for single paragraph content. Result will NOT be wrapped into <p> tags.

      Parameters

      • src: string
      • env: Env = {}

      Returns string