What's the reason behind commentTokens?

When reading @codemirror/lang-markdown, I noticed that the exported markdown() method creates a language with

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

I tried to use that very same logic in my code, I created something like this:

export function state(content: string): EditorState {
  return EditorState.create({
    doc: content,
    extensions: [
      new Language(Facet.define(), parser.configure([

And as you can see I didn’t add commentTokens, but I can see that html comment blocks and inline comments are being correctly parsed.

Why are commentTokens added in lang-markdown? Should I also add them to my code? Now that I didn’t add them, is there some edge case that doesn’t work?

I found that they are somehow connected to langauge data: CodeMirror Reference Manual but I didn’t add it, and the whole editor seems to work fine. Did I break some functionallity by not adding it? Or is this redundant?

They are used by toggleComment and related commands to comment and uncomment text.

1 Like