Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Djot support #12562

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
| devicetree | ✓ | | | |
| dhall | ✓ | ✓ | | `dhall-lsp-server` |
| diff | ✓ | | | |
| djot | ✓ | | | |
| docker-compose | ✓ | ✓ | ✓ | `docker-compose-langserver`, `yaml-language-server` |
| dockerfile | ✓ | ✓ | | `docker-langserver` |
| dot | ✓ | | | `dot-language-server` |
Expand Down
12 changes: 12 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,18 @@ grammar = "markdown_inline"
name = "markdown_inline"
source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-markdown", rev = "62516e8c78380e3b51d5b55727995d2c511436d8", subpath = "tree-sitter-markdown-inline" }

[[language]]
name = "djot"
scope = "source.djot"
injection-regex = "dj|djot"
file-types = ["dj", "djot"]
indent = { tab-width = 2, unit = " " }
block-comment-tokens = { start = "{%", end = "%}" }

[[grammar]]
name = "djot"
source = { git = "https://github.com/treeman/tree-sitter-djot", rev = "886601b67d1f4690173a4925c214343c30704d32" }

[[language]]
name = "dart"
scope = "source.dart"
Expand Down
311 changes: 311 additions & 0 deletions runtime/queries/djot/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
[
(footnote_marker_begin)
(footnote_marker_end)
] @punctuation.bracket

(footnote_reference (reference_label) @markup.link.label)

(footnote (reference_label) @markup.link.label)

[
(autolink)
(inline_link_destination)
(link_destination)
] @markup.link.url

(link_reference_definition (link_label) @markup.link.label)

(link_reference_definition
[
"["
"]"
] @punctuation.bracket)

(image_description
[
"["
"]"
] @punctuation.bracket)

(image_description) @label

(inline_image
[
"!["
"]"
] @punctuation.bracket)

(collapsed_reference_image
[
"!["
"]"
] @punctuation.bracket)

(collapsed_reference_image "[]" @punctuation.bracket)

(full_reference_image
[
"!["
"["
"]"
] @punctuation.bracket)

(full_reference_image (link_label) @markup.link.label)

(inline_link (link_text) @markup.link.text)

(collapsed_reference_link (link_text) @markup.link.text)

(full_reference_link
[
"["
"]"
] @punctuation.bracket)

(collapsed_reference_link "[]" @punctuation.bracket)

(full_reference_link (link_label) @markup.link.label)

(full_reference_link (link_text) @markup.link.text)

(link_reference_definition ":" @punctuation.delimiter)

(inline_link_destination
[
"("
")"
] @punctuation.bracket)

(autolink
[
"<"
">"
] @punctuation.bracket)

(link_text
[
"["
"]"
] @punctuation.bracket)

(key_value (value) @string)

(key_value (key) @attribute)

(key_value "=" @operator)

; NOTE: Not perfectly semantically accurate, but a fair approximation.
(identifier) @string.special.symbol
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally okay with variable or variable.other

Copy link
Author

@mmibbetson mmibbetson Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried a few things for identifiers and found that using more accurate scopes like type or attribute often made them indistinct from classes. Looking at variable and variable.other, there are a few themes where this looks nice but many of them have variables un-highlighted which kind of buries the identifiers by making them look like everything else.

My reasoning for using string.special.symbol was to at least emphasise the idea that there is only one instance of this thing 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning for using string.special.symbol was to at least emphasise the idea that there is only one instance of this thing

Understandable! However usually themes set the variable to a color because of their own specific reasons, and it's always a toss-up if somebody prefers semantics over UX.
I don't have any strong preference here, I'm already glad this PR is up!


[
(class)
(class_name)
] @type

(block_attribute
[
"{"
"}"
] @punctuation.bracket)

(inline_attribute
[
"{"
"}"
] @punctuation.bracket)

(span
[
"["
"]"
] @punctuation.bracket)

(comment
[
"{"
"}"
"%"
] @comment.block)

; INFO: djot only has block-scoped comments.
(comment) @comment.block

(raw_inline) @markup.raw

(verbatim) @markup.raw

(math) @markup.raw

([
(emphasis_begin)
(emphasis_end)
(strong_begin)
(strong_end)
(verbatim_marker_begin)
(verbatim_marker_end)
(math_marker)
(math_marker_begin)
(math_marker_end)
(raw_inline_attribute)
(raw_inline_marker_begin)
(raw_inline_marker_end)
] @punctuation.bracket)

(subscript
[
"~"
"{~"
"~}"
] @punctuation.bracket)

(superscript
[
"^"
"{^"
"^}"
] @punctuation.bracket)

(delete
[
"{-"
"-}"
] @punctuation.bracket)

(insert
[
"{+"
"+}"
] @punctuation.bracket)

; NOTE: 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.bracket)

; TEMP: Scope not available, with no appropriate alternative.
(subscript) @markup.subscript

; TEMP: Scope not available, with no appropriate alternative.
(superscript) @markup.superscript

; TEMP: Scope not available, with no appropriate alternative.
(highlighted) @markup.highlighted

; TEMP: Scope not available, with no appropriate alternative.
(insert) @markup.insert

(delete) @markup.strikethrough

; INFO: This applies to emojis.
(symbol) @string.special.symbol

(strong) @markup.bold

(emphasis) @markup.italic

(backslash_escape) @constant.character.escape

(hard_line_break) @constant.character.escape

((quotation_marks) @constant.character.escape
(#any-of? @constant.character.escape "\\\"" "\\'"))

; NOTE: Opting for this over the @punctuation.bracket used for things like
; {-delete-} to emphasise the semantic significance of specified opening/closing
; quotation marks.
(quotation_marks) @markup.quote

; INFO: `term` only matches on definition list items -- other list items won't be highlighted.
(list_item (term) @constructor)

[
(ellipsis)
(en_dash)
(em_dash)
] @punctuation.special

(checked
[
"x"
"X"
] @constant.builtin.boolean) @markup.list.checked

(list_marker_task (checked)) @markup.list.checked

(list_marker_task (unchecked)) @markup.list.unchecked

[
(list_marker_decimal_period)
(list_marker_decimal_paren)
(list_marker_decimal_parens)
(list_marker_lower_alpha_period)
(list_marker_lower_alpha_paren)
(list_marker_lower_alpha_parens)
(list_marker_upper_alpha_period)
(list_marker_upper_alpha_paren)
(list_marker_upper_alpha_parens)
(list_marker_lower_roman_period)
(list_marker_lower_roman_paren)
(list_marker_lower_roman_parens)
(list_marker_upper_roman_period)
(list_marker_upper_roman_paren)
(list_marker_upper_roman_parens)
] @markup.list.numbered

[
(list_marker_dash)
(list_marker_plus)
(list_marker_star)
(list_marker_definition)
] @markup.list.unnumbered

(table_caption) @label

(table_caption (marker) @punctuation.special)

(table_separator) @punctuation.special

(table_row "|" @punctuation.special)

(table_header "|" @punctuation.special)

(table_header) @markup.heading

(block_quote) @markup.quote

(block_quote_marker) @markup.quote

(language_marker) @punctuation.delimiter

(inline_attribute _ @attribute)

(language) @type.enum.variant

[
(code_block_marker_begin)
(code_block_marker_end)
(raw_block_marker_begin)
(raw_block_marker_end)
] @punctuation.bracket

[
(code_block)
(raw_block)
] @markup.raw.block

[
(div_marker_begin)
(div_marker_end)
] @tag

(thematic_break) @special

(heading1 (marker) @markup.heading.marker) @markup.heading.1
(heading2 (marker) @markup.heading.marker) @markup.heading.2
(heading3 (marker) @markup.heading.marker) @markup.heading.3
(heading4 (marker) @markup.heading.marker) @markup.heading.4
(heading5 (marker) @markup.heading.marker) @markup.heading.5
(heading6 (marker) @markup.heading.marker) @markup.heading.6
19 changes: 19 additions & 0 deletions runtime/queries/djot/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(comment (content) @injection.content
(#set! injection.language "comment"))

(math (content) @injection.content
(#set! injection.language "latex") (#set! injection.include-unnamed-children))

(code_block
(language) @injection.language
(code) @injection.content (#set! injection.include-unnamed-children))

(raw_block
(raw_block_info
(language) @injection.language)
(content) @injection.content (#set! injection.include-unnamed-children))

(raw_inline
(content) @injection.content (#set! injection.include-unnamed-children)
(raw_inline_attribute
(language) @injection.language))
Loading