Search code examples
javascriptmarkdownwmdwmd-markdown

Force WMD to use built-in preprocessor


I use wmd to all my projects but lately I wanted to add support for fenced code blocks and I saw that it is possible to achieve with preprocessors. I'm using something like this:

const content = wmd(myMarkdownString, {preprocessors: ['fencedCodeBlocks']});

But it doesn't work - throws error:

TypeError: fn is not a function

As I understand, I should pass there a function instead of string? But when I try to do it, I'm getting an error that fencedCodeBlocks variable is undefined but I don't know which object contain this method exactly (tried different options but without success).


Solution

  • From the wmd module documentation:

    wmd.preprocessors: An object containing core preprocessor functions:

    • fencedCodeBlocks - GitHub style fenced code blocks

    So the code should be:

    const content = wmd(myMarkdownString, {preprocessors: [wmd.preprocessors.fencedCodeBlocks]});