diff options
| author | Matthias Deiml <matthias@deiml.net> | 2022-06-26 18:02:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-26 18:02:29 +0200 |
| commit | 002084b1bea4311fdac184f080206bf890937d80 (patch) | |
| tree | 7215a635789883d0f7b00aca3d59a4f19a566b6e /queries | |
| parent | Chore: remove prefix from parser "location" property (diff) | |
| download | nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.gz nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.bz2 nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.lz nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.xz nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.zst nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.zip | |
feat(markdown)!: switch to split parser (#3048)
* switch to split markdown parser with separate block and inline parsers to improve performance
* add exclude_children! directive (useful for something like Injected markdown incorrectly highlights indented docstrings #2212)
* split markdown queries into block and inline ones and add the injection for inline into block grammar
* add include_dir option to parser configs (needed because the two grammars don't live in the repos root directory)
BREAKING CHANGE: downstream queries need to be adapted to new parser
Diffstat (limited to 'queries')
| -rw-r--r-- | queries/markdown/highlights.scm | 63 | ||||
| -rw-r--r-- | queries/markdown/injections.scm | 6 | ||||
| -rw-r--r-- | queries/markdown_inline/highlights.scm | 67 | ||||
| -rw-r--r-- | queries/markdown_inline/injections.scm | 1 |
4 files changed, 78 insertions, 59 deletions
diff --git a/queries/markdown/highlights.scm b/queries/markdown/highlights.scm index 9d6959b22..4cc81f9e7 100644 --- a/queries/markdown/highlights.scm +++ b/queries/markdown/highlights.scm @@ -1,6 +1,6 @@ -;; From MDeiml/tree-sitter-markdown -(atx_heading (heading_content) @text.title) -(setext_heading (heading_content) @text.title) +;From MDeiml/tree-sitter-markdown +(atx_heading (inline) @text.title) +(setext_heading (paragraph) @text.title) [ (atx_h1_marker) @@ -14,33 +14,23 @@ ] @punctuation.special [ - (code_span) (link_title) (indented_code_block) (fenced_code_block) ] @text.literal [ - (emphasis_delimiter) - (code_span_delimiter) (fenced_code_block_delimiter) ] @punctuation.delimiter (code_fence_content) @none -(emphasis) @text.emphasis - -(strong_emphasis) @text.strong - [ (link_destination) - (uri_autolink) ] @text.uri [ (link_label) - (link_text) - (image_description) ] @text.reference [ @@ -52,56 +42,17 @@ (thematic_break) ] @punctuation.special -(block_quote_marker) @punctuation.special +[ + (block_continuation) + (block_quote_marker) +] @punctuation.special [ (backslash_escape) - (hard_line_break) ] @string.escape -(image "!" @punctuation.delimiter) -(image "[" @punctuation.delimiter) -(image "]" @punctuation.delimiter) -(image "(" @punctuation.delimiter) -; (image ")" @punctuation.delimiter) - -(inline_link "[" @punctuation.delimiter) -(inline_link "]" @punctuation.delimiter) -(inline_link "(" @punctuation.delimiter) -; (inline_link ")" @punctuation.delimiter) - -(shortcut_link "[" @punctuation.delimiter) -(shortcut_link "]" @punctuation.delimiter) - ([ (info_string) (fenced_code_block_delimiter) - (code_span_delimiter) - (emphasis_delimiter) ] @conceal (#set! conceal "")) - - -; Conceal inline links -(inline_link - [ - "[" - "]" - "(" - (link_destination) - ")" -] @conceal -(#set! conceal "")) - - -; Conceal image links -(image - [ - "!" - "[" - "]" - "(" - (link_destination) - ")" -] @conceal - (#set! conceal "")) diff --git a/queries/markdown/injections.scm b/queries/markdown/injections.scm index 6fa047ac9..c5aca6c54 100644 --- a/queries/markdown/injections.scm +++ b/queries/markdown/injections.scm @@ -1,9 +1,9 @@ (fenced_code_block (info_string (language) @language) - (code_fence_content) @content) + (code_fence_content) @content (#exclude_children! @content)) ((html_block) @html) -((html_tag) @html) -(document . (thematic_break) (_) @yaml @combined (thematic_break)) +(document . (section . (thematic_break) (_) @yaml @combined (thematic_break))) +((inline) @markdown_inline (#exclude_children! @markdown_inline)) diff --git a/queries/markdown_inline/highlights.scm b/queries/markdown_inline/highlights.scm new file mode 100644 index 000000000..495e6f1ab --- /dev/null +++ b/queries/markdown_inline/highlights.scm @@ -0,0 +1,67 @@ +;; From MDeiml/tree-sitter-markdown +[ + (code_span) + (link_title) +] @text.literal + +[ + (emphasis_delimiter) + (code_span_delimiter) +] @punctuation.delimiter + +(emphasis) @text.emphasis + +(strong_emphasis) @text.strong + +[ + (link_destination) + (uri_autolink) +] @text.uri + +[ + (link_label) + (link_text) + (image_description) +] @text.reference + +[ + (backslash_escape) + (hard_line_break) +] @string.escape + +; "(" not part of query because of +; https://github.com/nvim-treesitter/nvim-treesitter/issues/2206 +; TODO: Find better fix for this +(image ["!" "[" "]" "("] @punctuation.delimiter) +(inline_link ["[" "]" "("] @punctuation.delimiter) +(shortcut_link ["[" "]"] @punctuation.delimiter) + +([ + (code_span_delimiter) + (emphasis_delimiter) +] @conceal +(#set! conceal "")) + +; Conceal inline links +(inline_link + [ + "[" + "]" + "(" + (link_destination) + ")" +] @conceal +(#set! conceal "")) + + +; Conceal image links +(image + [ + "!" + "[" + "]" + "(" + (link_destination) + ")" +] @conceal + (#set! conceal "")) diff --git a/queries/markdown_inline/injections.scm b/queries/markdown_inline/injections.scm new file mode 100644 index 000000000..5cf45dac2 --- /dev/null +++ b/queries/markdown_inline/injections.scm @@ -0,0 +1 @@ +((html_tag) @html) |
