Skip to content

parse function requires provideLexer and provideParser hooks to be defined when using custom hooks #3641

Closed
@lukasmatta

Description

@lukasmatta

Marked version:
15.0.7

Describe the bug
When providing only subset of hooks it fails on:

const lexer = opt.hooks ? opt.hooks.provideLexer() : (blockType ? _Lexer.lex : _Lexer.lexInline);
(if hooks is defined it expects provideLexer and provideParser functions to be defined as well)

To Reproduce

import { marked } from "marked";

const options = {
  hooks: {
    postprocess: (html) => html,
  },
};

// Run marked
console.log(marked.parse("# Test", options)); // TypeError: opt.hooks.provideLexer is not a function

Note that when providing options using the use function, it works:

import { marked } from "marked";

const options = {
  hooks: {
    postprocess: (html) => html,
  },
};

marked.use(options);

console.log(marked("# Test")); // <h1>Test</h1>

Expected behavior
I think it should be possible to provide only subset of hooks when using parse function as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions