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

dev for pandoc markdown treesitter grammar #160

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
14 changes: 11 additions & 3 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
QuartoPreview quarto.txt /*QuartoPreview*
quarto.nvim quarto.txt /*quarto.nvim*
quarto.quartoPreview() quarto.txt /*quarto.quartoPreview()*
quarto-links quarto.txt /*quarto-links*
quarto-quarto-nvim quarto.txt /*quarto-quarto-nvim*
quarto-quarto-nvim-available-commands quarto.txt /*quarto-quarto-nvim-available-commands*
quarto-quarto-nvim-language-support quarto.txt /*quarto-quarto-nvim-language-support*
quarto-quarto-nvim-recommended-plugins quarto.txt /*quarto-quarto-nvim-recommended-plugins*
quarto-quarto-nvim-running-code quarto.txt /*quarto-quarto-nvim-running-code*
quarto-quarto-nvim-setup quarto.txt /*quarto-quarto-nvim-setup*
quarto-quarto-nvim-usage quarto.txt /*quarto-quarto-nvim-usage*
quarto-quarto-nvim-walkthrough quarto.txt /*quarto-quarto-nvim-walkthrough*
quarto-table-of-contents quarto.txt /*quarto-table-of-contents*
quarto.txt quarto.txt /*quarto.txt*
4 changes: 3 additions & 1 deletion ftplugin/quarto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ vim.b.slime_cell_delimiter = '```'

-- TODO: Workaround while nvim-treesitter doesn't link those anymore
-- until our ouwn pandoc grammar is ready
vim.treesitter.language.register("markdown", { "quarto", "rmd" })
-- vim.treesitter.language.register("markdown", { "quarto", "rmd" })

vim.bo.commentstring = "<!-- %s -->"

local config = require('quarto.config').config
local quarto = require 'quarto'
Expand Down
7 changes: 7 additions & 0 deletions queries/pandoc_markdown/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
([
(fenced_code_block)
(indented_code_block)
(list)
(section)
] @fold
(#trim! @fold))
121 changes: 121 additions & 0 deletions queries/pandoc_markdown/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
;From MDeiml/tree-sitter-markdown & Helix
(setext_heading
(paragraph) @markup.heading.1
(setext_h1_underline) @markup.heading.1)

(setext_heading
(paragraph) @markup.heading.2
(setext_h2_underline) @markup.heading.2)

(atx_heading
(atx_h1_marker)) @markup.heading.1

(atx_heading
(atx_h2_marker)) @markup.heading.2

(atx_heading
(atx_h3_marker)) @markup.heading.3

(atx_heading
(atx_h4_marker)) @markup.heading.4

(atx_heading
(atx_h5_marker)) @markup.heading.5

(atx_heading
(atx_h6_marker)) @markup.heading.6

(info_string) @label

(pipe_table_header
(pipe_table_cell) @markup.heading)

(pipe_table_header
"|" @punctuation.special)

(pipe_table_row
"|" @punctuation.special)

(pipe_table_delimiter_row
"|" @punctuation.special)

(pipe_table_delimiter_cell) @punctuation.special

; Code blocks (conceal backticks and language annotation)
(indented_code_block) @markup.raw.block

((fenced_code_block) @markup.raw.block
(#set! priority 90))

(fenced_code_block
(fenced_code_block_delimiter) @markup.raw.block
(#set! conceal ""))

(fenced_code_block
(info_string
(language) @label
(#set! conceal "")))

(link_destination) @markup.link.url

[
(link_title)
(link_label)
] @markup.link.label

((link_label)
.
":" @punctuation.delimiter)

[
(list_marker_plus)
(list_marker_minus)
(list_marker_star)
(list_marker_dot)
(list_marker_parenthesis)
] @markup.list

; NOTE: The following has been commented out due to issues with spaces in the
; list marker nodes generated by the parser. If those spaces ever get captured
; by a different node (e.g. block_continuation) we can safely re-add these
; conceals.
; ;; Conceal bullet points
; ([(list_marker_plus) (list_marker_star)]
; @punctuation.special
; (#offset! @punctuation.special 0 0 0 -1)
; (#set! conceal "•"))
; ([(list_marker_plus) (list_marker_star)]
; @punctuation.special
; (#any-of? @punctuation.special "+" "*")
; (#set! conceal "•"))
; ((list_marker_minus)
; @punctuation.special
; (#offset! @punctuation.special 0 0 0 -1)
; (#set! conceal "—"))
; ((list_marker_minus)
; @punctuation.special
; (#eq? @punctuation.special "-")
; (#set! conceal "—"))
(thematic_break) @punctuation.special

(task_list_marker_unchecked) @markup.list.unchecked

(task_list_marker_checked) @markup.list.checked

((block_quote) @markup.quote
(#set! priority 90))

([
(plus_metadata)
(minus_metadata)
] @keyword.directive
(#set! priority 90))

[
(block_continuation)
(block_quote_marker)
] @punctuation.special

(backslash_escape) @string.escape

(inline) @spell
1 change: 1 addition & 0 deletions queries/pandoc_markdown/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(list_item) @indent.auto
26 changes: 26 additions & 0 deletions queries/pandoc_markdown/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(fenced_code_block
(info_string
(language) @_lang)
(code_fence_content) @injection.content
(#set-lang-from-info-string! @_lang))

((html_block) @injection.content
(#set! injection.language "html")
(#set! injection.combined)
(#set! injection.include-children))

((minus_metadata) @injection.content
(#set! injection.language "yaml")
(#offset! @injection.content 1 0 -1 0)
(#set! injection.include-children))

((plus_metadata) @injection.content
(#set! injection.language "toml")
(#offset! @injection.content 1 0 -1 0)
(#set! injection.include-children))

([
(inline)
(pipe_table_cell)
] @injection.content
(#set! injection.language "pandoc_markdown_inline"))
20 changes: 20 additions & 0 deletions queries/pandoc_markdown/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; extends
; (atx_heading
; heading_content: (_) @class.inner) @class.outer
;
; (setext_heading
; heading_content: (_) @class.inner) @class.outer
;
; (thematic_break) @class.outer


(fenced_code_block (code_fence_content) @class.inner) @class.outer

(paragraph) @function.outer @function.inner

(fenced_code_block (code_fence_content) @block.inner) @block.outer

[
(paragraph)
(list)
] @block.outer
132 changes: 132 additions & 0 deletions queries/pandoc_markdown_inline/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
; From MDeiml/tree-sitter-markdown
(code_span) @markup.raw @nospell

(emphasis) @markup.italic

(strong_emphasis) @markup.strong

(strikethrough) @markup.strikethrough

(shortcut_link
(link_text) @nospell)

[
(backslash_escape)
(hard_line_break)
] @string.escape

; Conceal codeblock and text style markers
([
(code_span_delimiter)
(emphasis_delimiter)
] @conceal
(#set! conceal ""))

; Conceal inline links
(inline_link
[
"["
"]"
"("
(link_destination)
")"
] @markup.link
(#set! conceal ""))

[
(link_label)
(link_text)
(link_title)
(image_description)
] @markup.link.label

((inline_link
(link_destination) @_url) @_label
(#set! @_label url @_url))

((image
(link_destination) @_url) @_label
(#set! @_label url @_url))

; Conceal image links
(image
[
"!"
"["
"]"
"("
(link_destination)
")"
] @markup.link
(#set! conceal ""))

; Conceal full reference links
(full_reference_link
[
"["
"]"
(link_label)
] @markup.link
(#set! conceal ""))

; Conceal collapsed reference links
(collapsed_reference_link
[
"["
"]"
] @markup.link
(#set! conceal ""))

; Conceal shortcut links
(shortcut_link
[
"["
"]"
] @markup.link
(#set! conceal ""))

[
(link_destination)
(uri_autolink)
(email_autolink)
] @markup.link.url @nospell

((uri_autolink) @_url
(#offset! @_url 0 1 0 -1)
(#set! @_url url @_url))

(entity_reference) @nospell

; Replace common HTML entities.
((entity_reference) @character.special
(#eq? @character.special "&nbsp;")
(#set! conceal " "))

((entity_reference) @character.special
(#eq? @character.special "&lt;")
(#set! conceal "<"))

((entity_reference) @character.special
(#eq? @character.special "&gt;")
(#set! conceal ">"))

((entity_reference) @character.special
(#eq? @character.special "&amp;")
(#set! conceal "&"))

((entity_reference) @character.special
(#eq? @character.special "&quot;")
(#set! conceal "\""))

((entity_reference) @character.special
(#any-of? @character.special "&ensp;" "&emsp;")
(#set! conceal " "))


(strikethrough
(emphasis_delimiter)
(strikethrough
(emphasis_delimiter)
(emphasis_delimiter))
(emphasis_delimiter))@markup.doublestrikethrough

7 changes: 7 additions & 0 deletions queries/pandoc_markdown_inline/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
((html_tag) @injection.content
(#set! injection.language "html")
(#set! injection.combined))

((latex_block) @injection.content
(#set! injection.language "latex")
(#set! injection.include-children))
Loading