Skip to content

Commit c249669

Browse files
committed
dev for pandoc markdown treesitter grammar
1 parent aa6e0a9 commit c249669

File tree

9 files changed

+328
-4
lines changed

9 files changed

+328
-4
lines changed

doc/tags

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
QuartoPreview quarto.txt /*QuartoPreview*
2-
quarto.nvim quarto.txt /*quarto.nvim*
3-
quarto.quartoPreview() quarto.txt /*quarto.quartoPreview()*
1+
quarto-links quarto.txt /*quarto-links*
2+
quarto-quarto-nvim quarto.txt /*quarto-quarto-nvim*
3+
quarto-quarto-nvim-available-commands quarto.txt /*quarto-quarto-nvim-available-commands*
4+
quarto-quarto-nvim-language-support quarto.txt /*quarto-quarto-nvim-language-support*
5+
quarto-quarto-nvim-recommended-plugins quarto.txt /*quarto-quarto-nvim-recommended-plugins*
6+
quarto-quarto-nvim-running-code quarto.txt /*quarto-quarto-nvim-running-code*
7+
quarto-quarto-nvim-setup quarto.txt /*quarto-quarto-nvim-setup*
8+
quarto-quarto-nvim-usage quarto.txt /*quarto-quarto-nvim-usage*
9+
quarto-quarto-nvim-walkthrough quarto.txt /*quarto-quarto-nvim-walkthrough*
10+
quarto-table-of-contents quarto.txt /*quarto-table-of-contents*
11+
quarto.txt quarto.txt /*quarto.txt*

ftplugin/quarto.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ vim.b.slime_cell_delimiter = '```'
22

33
-- TODO: Workaround while nvim-treesitter doesn't link those anymore
44
-- until our ouwn pandoc grammar is ready
5-
vim.treesitter.language.register("markdown", { "quarto", "rmd" })
5+
-- vim.treesitter.language.register("markdown", { "quarto", "rmd" })
6+
7+
vim.bo.commentstring = "<!-- %s -->"
68

79
local config = require('quarto.config').config
810
local quarto = require 'quarto'

queries/pandoc_markdown/folds.scm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
([
2+
(fenced_code_block)
3+
(indented_code_block)
4+
(list)
5+
(section)
6+
] @fold
7+
(#trim! @fold))
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
;From MDeiml/tree-sitter-markdown & Helix
2+
(setext_heading
3+
(paragraph) @markup.heading.1
4+
(setext_h1_underline) @markup.heading.1)
5+
6+
(setext_heading
7+
(paragraph) @markup.heading.2
8+
(setext_h2_underline) @markup.heading.2)
9+
10+
(atx_heading
11+
(atx_h1_marker)) @markup.heading.1
12+
13+
(atx_heading
14+
(atx_h2_marker)) @markup.heading.2
15+
16+
(atx_heading
17+
(atx_h3_marker)) @markup.heading.3
18+
19+
(atx_heading
20+
(atx_h4_marker)) @markup.heading.4
21+
22+
(atx_heading
23+
(atx_h5_marker)) @markup.heading.5
24+
25+
(atx_heading
26+
(atx_h6_marker)) @markup.heading.6
27+
28+
(info_string) @label
29+
30+
(pipe_table_header
31+
(pipe_table_cell) @markup.heading)
32+
33+
(pipe_table_header
34+
"|" @punctuation.special)
35+
36+
(pipe_table_row
37+
"|" @punctuation.special)
38+
39+
(pipe_table_delimiter_row
40+
"|" @punctuation.special)
41+
42+
(pipe_table_delimiter_cell) @punctuation.special
43+
44+
; Code blocks (conceal backticks and language annotation)
45+
(indented_code_block) @markup.raw.block
46+
47+
((fenced_code_block) @markup.raw.block
48+
(#set! priority 90))
49+
50+
(fenced_code_block
51+
(fenced_code_block_delimiter) @markup.raw.block
52+
(#set! conceal ""))
53+
54+
(fenced_code_block
55+
(info_string
56+
(language) @label
57+
(#set! conceal "")))
58+
59+
(link_destination) @markup.link.url
60+
61+
[
62+
(link_title)
63+
(link_label)
64+
] @markup.link.label
65+
66+
((link_label)
67+
.
68+
":" @punctuation.delimiter)
69+
70+
[
71+
(list_marker_plus)
72+
(list_marker_minus)
73+
(list_marker_star)
74+
(list_marker_dot)
75+
(list_marker_parenthesis)
76+
] @markup.list
77+
78+
; NOTE: The following has been commented out due to issues with spaces in the
79+
; list marker nodes generated by the parser. If those spaces ever get captured
80+
; by a different node (e.g. block_continuation) we can safely re-add these
81+
; conceals.
82+
; ;; Conceal bullet points
83+
; ([(list_marker_plus) (list_marker_star)]
84+
; @punctuation.special
85+
; (#offset! @punctuation.special 0 0 0 -1)
86+
; (#set! conceal "•"))
87+
; ([(list_marker_plus) (list_marker_star)]
88+
; @punctuation.special
89+
; (#any-of? @punctuation.special "+" "*")
90+
; (#set! conceal "•"))
91+
; ((list_marker_minus)
92+
; @punctuation.special
93+
; (#offset! @punctuation.special 0 0 0 -1)
94+
; (#set! conceal "—"))
95+
; ((list_marker_minus)
96+
; @punctuation.special
97+
; (#eq? @punctuation.special "-")
98+
; (#set! conceal "—"))
99+
(thematic_break) @punctuation.special
100+
101+
(task_list_marker_unchecked) @markup.list.unchecked
102+
103+
(task_list_marker_checked) @markup.list.checked
104+
105+
((block_quote) @markup.quote
106+
(#set! priority 90))
107+
108+
([
109+
(plus_metadata)
110+
(minus_metadata)
111+
] @keyword.directive
112+
(#set! priority 90))
113+
114+
[
115+
(block_continuation)
116+
(block_quote_marker)
117+
] @punctuation.special
118+
119+
(backslash_escape) @string.escape
120+
121+
(inline) @spell

queries/pandoc_markdown/indents.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(list_item) @indent.auto
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(fenced_code_block
2+
(info_string
3+
(language) @_lang)
4+
(code_fence_content) @injection.content
5+
(#set-lang-from-info-string! @_lang))
6+
7+
((html_block) @injection.content
8+
(#set! injection.language "html")
9+
(#set! injection.combined)
10+
(#set! injection.include-children))
11+
12+
((minus_metadata) @injection.content
13+
(#set! injection.language "yaml")
14+
(#offset! @injection.content 1 0 -1 0)
15+
(#set! injection.include-children))
16+
17+
((plus_metadata) @injection.content
18+
(#set! injection.language "toml")
19+
(#offset! @injection.content 1 0 -1 0)
20+
(#set! injection.include-children))
21+
22+
([
23+
(inline)
24+
(pipe_table_cell)
25+
] @injection.content
26+
(#set! injection.language "pandoc_markdown_inline"))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; extends
2+
; (atx_heading
3+
; heading_content: (_) @class.inner) @class.outer
4+
;
5+
; (setext_heading
6+
; heading_content: (_) @class.inner) @class.outer
7+
;
8+
; (thematic_break) @class.outer
9+
10+
11+
(fenced_code_block (code_fence_content) @class.inner) @class.outer
12+
13+
(paragraph) @function.outer @function.inner
14+
15+
(fenced_code_block (code_fence_content) @block.inner) @block.outer
16+
17+
[
18+
(paragraph)
19+
(list)
20+
] @block.outer
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
; From MDeiml/tree-sitter-markdown
2+
(code_span) @markup.raw @nospell
3+
4+
(emphasis) @markup.italic
5+
6+
(strong_emphasis) @markup.strong
7+
8+
(strikethrough) @markup.strikethrough
9+
10+
(shortcut_link
11+
(link_text) @nospell)
12+
13+
[
14+
(backslash_escape)
15+
(hard_line_break)
16+
] @string.escape
17+
18+
; Conceal codeblock and text style markers
19+
([
20+
(code_span_delimiter)
21+
(emphasis_delimiter)
22+
] @conceal
23+
(#set! conceal ""))
24+
25+
; Conceal inline links
26+
(inline_link
27+
[
28+
"["
29+
"]"
30+
"("
31+
(link_destination)
32+
")"
33+
] @markup.link
34+
(#set! conceal ""))
35+
36+
[
37+
(link_label)
38+
(link_text)
39+
(link_title)
40+
(image_description)
41+
] @markup.link.label
42+
43+
((inline_link
44+
(link_destination) @_url) @_label
45+
(#set! @_label url @_url))
46+
47+
((image
48+
(link_destination) @_url) @_label
49+
(#set! @_label url @_url))
50+
51+
; Conceal image links
52+
(image
53+
[
54+
"!"
55+
"["
56+
"]"
57+
"("
58+
(link_destination)
59+
")"
60+
] @markup.link
61+
(#set! conceal ""))
62+
63+
; Conceal full reference links
64+
(full_reference_link
65+
[
66+
"["
67+
"]"
68+
(link_label)
69+
] @markup.link
70+
(#set! conceal ""))
71+
72+
; Conceal collapsed reference links
73+
(collapsed_reference_link
74+
[
75+
"["
76+
"]"
77+
] @markup.link
78+
(#set! conceal ""))
79+
80+
; Conceal shortcut links
81+
(shortcut_link
82+
[
83+
"["
84+
"]"
85+
] @markup.link
86+
(#set! conceal ""))
87+
88+
[
89+
(link_destination)
90+
(uri_autolink)
91+
(email_autolink)
92+
] @markup.link.url @nospell
93+
94+
((uri_autolink) @_url
95+
(#offset! @_url 0 1 0 -1)
96+
(#set! @_url url @_url))
97+
98+
(entity_reference) @nospell
99+
100+
; Replace common HTML entities.
101+
((entity_reference) @character.special
102+
(#eq? @character.special "&nbsp;")
103+
(#set! conceal " "))
104+
105+
((entity_reference) @character.special
106+
(#eq? @character.special "&lt;")
107+
(#set! conceal "<"))
108+
109+
((entity_reference) @character.special
110+
(#eq? @character.special "&gt;")
111+
(#set! conceal ">"))
112+
113+
((entity_reference) @character.special
114+
(#eq? @character.special "&amp;")
115+
(#set! conceal "&"))
116+
117+
((entity_reference) @character.special
118+
(#eq? @character.special "&quot;")
119+
(#set! conceal "\""))
120+
121+
((entity_reference) @character.special
122+
(#any-of? @character.special "&ensp;" "&emsp;")
123+
(#set! conceal " "))
124+
125+
126+
(strikethrough
127+
(emphasis_delimiter)
128+
(strikethrough
129+
(emphasis_delimiter)
130+
(emphasis_delimiter))
131+
(emphasis_delimiter))@markup.doublestrikethrough
132+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
((html_tag) @injection.content
2+
(#set! injection.language "html")
3+
(#set! injection.combined))
4+
5+
((latex_block) @injection.content
6+
(#set! injection.language "latex")
7+
(#set! injection.include-children))

0 commit comments

Comments
 (0)