In markdown, headings are represented by one or more hashtags at the start of a line followed by a space. In cm6, the space is used to identify headings but in the syntax tree / dom the space is part of the Heading text rather than the HeaderMark. Is that a feature or a bug? I typically think of the space as part of the markup not the text (it distinguishes headings from other text like hashtags and, when md is converted to html, both the hashtag(s) and the space are replaced by the opening < h1 > tag). But I’m just starting to get familiar with codemirror 6 so I might be missing something obvious.
My first question is what are you doing that causes this to actually matter?
I am experimenting with styling / hiding the heading tags separately from the heading text and running into issues where the text doesn’t align because it has leading whitespace.
I see. And special-casing your styling logic to adjust for this isn’t doable? I think most people would expect marker tokens in the syntax tree to cover only the actual symbol. The same issue exists with lists. And possibly leading space in code blocks.
Sorry for the delayed response. I wanted to get a better understanding of how the highlighter and markdown parser worked so I wasn’t wasting your time.
I don’t know of any way to fix the header issue with styling alone. The content would need to be trimmed.
I agree. The trouble is you would also expect the heading to only cover the actual heading. And the space is not part of the heading. Is this weirdness unique to markdown?
I’d argue that in md the space is part of the token for block level elements like headings and quotes. The original ATX mark for quotes was nothing but three leading spaces. But I have no idea what that means for cm6. After looking at the parser in more detail and building a few md extensions, I have a better appreciation of just how complex parsing md is.
I assume you are using some kind of
replace decorations to hide markup—when generating those you could, for header markup, include the space after the markup in the replaced range.
Thanks. That’s exactly what I’m doing and it works well.