foldNodeProp does not seem to work for ATX heading

I am trying to fold ATX heading of a markdown language using foldNodeProp. But, it does not seem to work for ATX heading.

The following code is for illustrative purposes only. I expected logs starting with ‘B’ to be output for ATX heading also, but in fact only Setex heading was output.
How do I make ATX heading foldable?

Thanks in advance


import { Language, defineLanguageFacet, languageDataProp, foldNodeProp, indentNodeProp } from '@codemirror/language';
import { parser as baseParser } from '@lezer/markdown';

const data = defineLanguageFacet({block: {open: "<!--", close: "-->"}})

function mkLang(parser) {
  return new Language(data, parser, parser.nodeSet.types.find(t => == "Document"));

const parser = baseParser.configure({
  props: [
    foldNodeProp.add((type) => {
      if ('ATXHeading') ||'SetextHeading')) {
        console.log(`A: ${}`);
        return (tree, state) => {
          console.log(`B: ${}`);
          return { from: state.doc.lineAt(tree.from).to, to: };
      if (!'Block') ||'Document')) return undefined;
      return (tree, state) => ({ from: state.doc.lineAt(tree.from).to, to: });
      Document: () => null,
      Document: data,

const language = mkLang(parser);

export default language;


import { basicSetup, EditorView } from '@codemirror/basic-setup';
import { EditorState } from '@codemirror/state';
import { markdown } from '@codemirror/lang-markdown';
import language from './language';

const doc =
`# ATX heading 1

## ATX heading 2

Setext heading 1

Setext heading 2

const state = EditorState.create({
  extensions: [
      base: language,

const view = new EditorView({
  parent: document.body


A: ATXHeading1
A: ATXHeading2
A: ATXHeading3
A: ATXHeading4
A: ATXHeading5
A: ATXHeading6
A: SetextHeading1
A: SetextHeading2
B: SetextHeading1
B: SetextHeading2

foldNodeProp is used to make the extent of certain syntax nodes foldable. Since a heading node only spans the actual heading, if you’re expecting this to fold that heading plus any content below it, that won’t work.

if you’re expecting this to fold that heading plus any content below it, that won’t work.

My actual code serves that purpose by traversing nodes, and it worked fine for Setext heading, but the process was not called for ATX heading.

I am wondering why ‘console.log(`B: ${}`);’ in language.js is not called for ATX headings.

Thanks for the reply.

The folding system will only call this for nodes that span across the end of the line that’s being folded.