codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.94k stars 376 forks source link

@codemirror/lang-markdown: specifying code block language removes monospace tag handling #1455

Closed stwlam closed 1 month ago

stwlam commented 1 month ago

Describe the issue

A markdown code block can be handled in syntax highlighting with the monospace tag. But if a language is specified, monospace tagging is no longer applied. A use case for this might be to indent or set a background for all code blocks while still providing language-specific syntax highlighting.

Browser and platform

No response

Reproduction link

https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge21hcmtkb3dufSBmcm9tICJAY29kZW1pcnJvci9sYW5nLW1hcmtkb3duIgppbXBvcnQge2xhbmd1YWdlc30gZnJvbSAiQGNvZGVtaXJyb3IvbGFuZ3VhZ2UtZGF0YSIKaW1wb3J0IHtIaWdobGlnaHRTdHlsZSwgc3ludGF4SGlnaGxpZ2h0aW5nfSBmcm9tICJAY29kZW1pcnJvci9sYW5ndWFnZSIKaW1wb3J0IHt0YWdzfSBmcm9tICJAbGV6ZXIvaGlnaGxpZ2h0IgoKLy8gVGhlIE1hcmtkb3duIHBhcnNlciB3aWxsIGR5bmFtaWNhbGx5IGxvYWQgcGFyc2VycwovLyBmb3IgY29kZSBibG9ja3MsIHVzaW5nIEBjb2RlbWlycm9yL2xhbmd1YWdlLWRhdGEgdG8KLy8gbG9vayB1cCB0aGUgYXBwcm9wcmlhdGUgZHluYW1pYyBpbXBvcnQuCmxldCB2aWV3ID0gbmV3IEVkaXRvclZpZXcoewogIGRvYzogIkhlbGxvXG5cbmBgYFxubGV0IHggPSAneSdcbmBgYFxuXG5gYGBqYXZhc2NyaXB0XG5sZXQgeCA9ICd5J1xuYGBgIiwKICBleHRlbnNpb25zOiBbCiAgICBiYXNpY1NldHVwLAogICAgbWFya2Rvd24oe2NvZGVMYW5ndWFnZXM6IGxhbmd1YWdlc30pLAogICAgc3ludGF4SGlnaGxpZ2h0aW5nKEhpZ2hsaWdodFN0eWxlLmRlZmluZShbCiAgICAgIHsgdGFnOiB0YWdzLm1vbm9zcGFjZSwgY2xhc3M6ICJtb25vc3BhY2UiIH0sCiAgICAgIHsgdGFnOiB0YWdzLmtleXdvcmQsIGNsYXNzOiAia2V5d29yZCIgfSwKICAgICAgewogICAgICAgIHRhZzogdGFncy5kZWZpbml0aW9uKHRhZ3MudmFyaWFibGVOYW1lKSwKICAgICAgICBjbGFzczogInZhci1uYW1lIgogICAgICB9LAogICAgICB7IHRhZzogdGFncy5zdHJpbmcsIGNsYXNzOiAic3RyaW5nIiB9CiAgICBdKSkKICBdLAogIHBhcmVudDogZG9jdW1lbnQuYm9keQp9KQo=

marijnh commented 1 month ago

Syntax tree overlays (which is the mechanism the Markdown parser uses to put the syntax tree of the nested languages into the markdown tree) will replace any nodes in the parent tree that they cover entirely. In this case, that means that the CodeText nodes of a highlighted fenced block will not participate in the highlighting of the code, since another tree is active at that point.

You could try to get the effect you want with scoped highlighter instead.