Extend markdown parser

Hello
I have written extension to the Markdown parser @lezer/markdown.

import { Input } from '@lezer/common';
import { BlockContext, Line, MarkdownConfig } from '@lezer/markdown';

declare module "@lezer/markdown" {
    interface BlockContext {
      readonly input: Input;
      checkedYaml: boolean | null;
    }
  }

export const YAMLFrontMatter: MarkdownConfig = {
    defineNodes: ["YAMLFrontMatter", "YAMLMarker", "YAMLContent"],
    parseBlock: [
      {
        name: "YAMLFrontMatter",
        parse(cx: BlockContext, line: Line) {
          if (cx.checkedYaml) {
            return false;
          }
          cx.checkedYaml = true;
          const fmRegex = /(^|^\s*\n)(---\n.+?\n---)/s;
          const match = fmRegex.exec(cx.input.chunk(0));
          if (match) {
            const start = match[1].length;
            const end = start + match[2].length;
            cx.addElement(
              cx.elt("YAMLFrontMatter", start, end, [
                cx.elt("YAMLMarker", start, start + 3),
                cx.elt("YAMLContent", start + 4, end - 4),
                cx.elt("YAMLMarker", end - 3, end),
              ])
            );
            while (cx.lineStart + line.text.length < end && cx.nextLine()) {}
            line.pos = 3;
            return true;
          }
          return false;
        },
        before: "LinkReference",
      },
    ],
  };

This way I can extend the base parser from @lezer/markdown by:

import { parser as baseMarkdownParser } from '@lezer/markdown'
const mdParser = baseMarkdownParser.configure([YAMLFrontMatter])

which seems to work fine. Now I want to integrate it to the markdown setup:

  const basicSetup = markdown({
    base: markdownLanguage,
    codeLanguages: languages,
  })

I cannot find a way to extend the parser, so that I can see the YAML nodes in my tree.

The @codemirror/lang-yaml package already provides a frontmatter helper if that’s what you’re trying to implement.

Thanks for the response

Frankly, I just want to implement some extension which would work with the markdownLanguage and be able to highlight it properly with custom tags. For now I cannot get it working

I don’t see your code assigning any style tags to the nodes you define, which would be needed to highlight them.