Skip to content

Commit

Permalink
markdown: improve fenced code block highlights
Browse files Browse the repository at this point in the history
This includes an update to tree-sitter markdown that adds an `info_string`
field to `fenced_code_block`. We can use that new `info_string` field with
the negation operator to prevent highlighting fenced code blocks that have
a language string as `markup.raw.block`.
  • Loading branch information
the-mikedavis committed Jun 29, 2022
1 parent b757da9 commit 83d2c1e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "markdown"
source = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "ad8c32917a16dfbb387d1da567bf0c3fb6fffde2" }
source = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "ab15701d8f3f68aeb74e30573b7d669a6ef2a7ed" }

[[language]]
name = "dart"
Expand Down
8 changes: 6 additions & 2 deletions runtime/queries/markdown/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
(atx_heading (atx_h5_marker) @markup.heading.marker (heading_content) @markup.heading.5)
(atx_heading (atx_h6_marker) @markup.heading.marker (heading_content) @markup.heading.6)

(code_fence_content) @none
(info_string) @label

(fenced_code_block
!info_string
(code_fence_content) @markup.raw.block)

[
(indented_code_block)
(fenced_code_block)
(fenced_code_block_delimiter)
] @markup.raw.block

(block_quote) @markup.quote
Expand Down
2 changes: 1 addition & 1 deletion runtime/queries/markdown/injections.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(fenced_code_block
(info_string) @injection.language
info_string: (info_string) @injection.language
(code_fence_content) @injection.content
(#set! injection.include-children))

Expand Down

0 comments on commit 83d2c1e

Please sign in to comment.