diff options
| -rw-r--r-- | queries/djot/folds.scm | 7 | ||||
| -rw-r--r-- | queries/djot/highlights.scm | 226 | ||||
| -rw-r--r-- | queries/djot/indents.scm | 10 | ||||
| -rw-r--r-- | queries/djot/locals.scm | 17 |
4 files changed, 207 insertions, 53 deletions
diff --git a/queries/djot/folds.scm b/queries/djot/folds.scm new file mode 100644 index 000000000..94f3724eb --- /dev/null +++ b/queries/djot/folds.scm @@ -0,0 +1,7 @@ +[ + (section) + (code_block) + (raw_block) + (list) + (div) +] @fold diff --git a/queries/djot/highlights.scm b/queries/djot/highlights.scm index 42e7a0ceb..e788891e0 100644 --- a/queries/djot/highlights.scm +++ b/queries/djot/highlights.scm @@ -21,7 +21,7 @@ (code_block) (raw_block) (frontmatter) -] @markup.raw +] @markup.raw.block (#set! "priority" 90)) ; Remove @markup.raw for code with a language spec @@ -29,7 +29,8 @@ . (code_block_marker_begin) (language) - (code) @none) + (code) @none + (#set! "priority" 90)) [ (code_block_marker_begin) @@ -38,7 +39,11 @@ (raw_block_marker_end) ] @punctuation.delimiter -(language) @label +(language) @attribute + +(inline_attribute + _ @conceal + (#set! conceal "")) ((language_marker) @punctuation.delimiter (#set! conceal "")) @@ -60,7 +65,7 @@ (table_caption (marker) @punctuation.special) -(table_caption) @markup.heading +(table_caption) @markup.italic [ (list_marker_dash) @@ -85,10 +90,14 @@ ] @markup.list (list_marker_task - (unchecked) @constant.builtin) @markup.list.unchecked + (unchecked)) @markup.list.unchecked (list_marker_task - (checked) @constant.builtin) @markup.list.checked + (checked)) @markup.list.checked + +; Colorize `x` in `[x]` +((checked) @constant.builtin + (#offset! @constant.builtin 0 1 0 -1)) [ (ellipsis) @@ -97,94 +106,137 @@ (quotation_marks) ] @string.special +(list_item + (term) @type.definition) + +; Conceal { and } but leave " and ' +((quotation_marks) @string.special + (#any-of? @string.special "\"}" "'}") + (#offset! @string.special 0 1 0 0) + (#set! conceal "")) + +((quotation_marks) @string.special + (#any-of? @string.special "\\\"" "\\'" "{'" "{\"") + (#offset! @string.special 0 0 0 -1) + (#set! conceal "")) + +[ + (hard_line_break) + (backslash_escape) +] @string.escape + +; Only conceal \ but leave escaped character. +((backslash_escape) @string.escape + (#offset! @string.escape 0 0 0 -1) + (#set! conceal "")) + (frontmatter_marker) @punctuation.delimiter (emphasis) @markup.italic (strong) @markup.strong -(emphasis - (emphasis_begin) @punctuation.delimiter) +(symbol) @string.special.symbol -(emphasis - (emphasis_end) @punctuation.delimiter) +(insert) @markup.underline -(strong - (strong_begin) @punctuation.delimiter) +(delete) @markup.strikethrough -(strong - (strong_end) @punctuation.delimiter) +[ + (highlighted) + (superscript) + (subscript) +] @string.special +; We need to target tokens specifically because `{=` etc can exist as fallback symbols in +; regular text, which we don't want to highlight or conceal. (highlighted [ "{=" "=}" - ] @punctuation.delimiter) + ] @punctuation.delimiter + (#set! conceal "")) (insert [ "{+" "+}" - ] @punctuation.delimiter) + ] @punctuation.delimiter + (#set! conceal "")) (delete [ "{-" "-}" - ] @punctuation.delimiter) + ] @punctuation.delimiter + (#set! conceal "")) (superscript [ "^" "{^" "^}" - ] @punctuation.delimiter) + ] @punctuation.delimiter + (#set! conceal "")) (subscript [ "~" "{~" "~}" - ] @punctuation.delimiter) - -(verbatim) @markup.raw + ] @punctuation.delimiter + (#set! conceal "")) -[ +([ + (emphasis_begin) + (emphasis_end) + (strong_begin) + (strong_end) (verbatim_marker_begin) (verbatim_marker_end) -] @punctuation.delimiter - -(math) @markup.math - -[ (math_marker) (math_marker_begin) (math_marker_end) -] @punctuation.delimiter - -(raw_inline) @markup.raw - -[ (raw_inline_attribute) (raw_inline_marker_begin) (raw_inline_marker_end) ] @punctuation.delimiter + (#set! conceal "")) -[ - "{" - "}" - "![" - "[" - "]" - "(" - ")" - "<" - ">" -] @punctuation.bracket +((math) @markup.math + (#set! "priority" 90)) -(comment) @comment +(verbatim) @markup.raw -(class) @type +((raw_inline) @markup.raw + (#set! "priority" 90)) + +(comment + "%" @comment + (#set! conceal "")) + +(span + [ + "[" + "]" + ] @punctuation.bracket) + +(inline_attribute + [ + "{" + "}" + ] @punctuation.bracket) + +(block_attribute + [ + "{" + "}" + ] @punctuation.bracket) + +[ + (class) + (class_name) +] @type (identifier) @tag @@ -197,10 +249,23 @@ (key_value (value) @string) -[ - (backslash_escape) - (hard_line_break) -] @string.escape +(link_text + [ + "[" + "]" + ] @punctuation.bracket + (#set! conceal "")) + +(autolink + [ + "<" + ">" + ] @punctuation.bracket + (#set! conceal "")) + +(inline_link + (inline_link_destination) @markup.link.url + (#set! conceal "")) (link_reference_definition ":" @punctuation.special) @@ -209,7 +274,19 @@ (link_text) @markup.link) (full_reference_link - (link_label) @markup.link.label) + (link_label) @markup.link.label + (#set! conceal "")) + +(collapsed_reference_link + "[]" @punctuation.bracket + (#set! conceal "")) + +(full_reference_link + [ + "[" + "]" + ] @punctuation.bracket + (#set! conceal "")) (collapsed_reference_link (link_text) @markup.link) @@ -223,11 +300,48 @@ (full_reference_image (link_label) @markup.link.label) -(image_description) @markup.link.label +(full_reference_image + [ + "![" + "[" + "]" + ] @punctuation.bracket) + +(collapsed_reference_image + [ + "![" + "]" + ] @punctuation.bracket) + +(inline_image + [ + "![" + "]" + ] @punctuation.bracket) + +(image_description) @markup.italic + +(image_description + [ + "[" + "]" + ] @punctuation.bracket) + +(link_reference_definition + [ + "[" + "]" + ] @punctuation.bracket) (link_reference_definition (link_label) @markup.link.label) +(inline_link_destination + [ + "(" + ")" + ] @punctuation.bracket) + [ (autolink) (inline_link_destination) @@ -236,16 +350,22 @@ ] @markup.link.url (footnote - (reference_label) @markup.link) + (reference_label) @markup.link.label) (footnote_reference - (reference_label) @markup.link) + (reference_label) @markup.link.label) [ (footnote_marker_begin) (footnote_marker_end) ] @punctuation.bracket +(todo) @comment.todo + +(note) @comment.note + +(fixme) @comment.error + [ (paragraph) (comment) diff --git a/queries/djot/indents.scm b/queries/djot/indents.scm new file mode 100644 index 000000000..3b1a56ebd --- /dev/null +++ b/queries/djot/indents.scm @@ -0,0 +1,10 @@ +; The intention here is to rely on Neovims `autoindent` setting. +; This allows us to not indent after just a single list item +; so we can create narrow lists quickly, but indent blocks inside list items +; to the previous paragraph. +(list_item_content) @indent.auto + +(footnote_content) @indent.align + +((table_caption) @indent.begin + (#set! indent.immediate 1)) diff --git a/queries/djot/locals.scm b/queries/djot/locals.scm new file mode 100644 index 000000000..1ac27529f --- /dev/null +++ b/queries/djot/locals.scm @@ -0,0 +1,17 @@ +(link_reference_definition + (link_label) @local.definition) + +(footnote + (reference_label) @local.definition) + +(collapsed_reference_link + (link_text) @local.reference) + +(full_reference_link + (link_label) @local.reference) + +(full_reference_image + (link_label) @local.reference) + +(footnote_reference + (reference_label) @local.reference) |
