Skip to content

Commit 418d311

Browse files
authored
feat(ft): add quarto support (#301)
`quarto` is built on top `markdown` syntax. Docs: https://quarto.org/
1 parent 1cd8e25 commit 418d311

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lua/Comment/ft.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ local L = setmetatable({
104104
python = { M.hash }, -- Python doesn't have block comments
105105
php = { M.cxx_l, M.cxx_b },
106106
prisma = { M.cxx_l },
107+
quarto = { M.html, M.html },
107108
r = { M.hash }, -- R doesn't have block comments
108109
readline = { M.hash },
109110
rego = { M.hash },
@@ -146,6 +147,13 @@ local L = setmetatable({
146147
end,
147148
})
148149

150+
---Maps a filteype to a parsername for filetypes
151+
---that don't have their own parser (yet).
152+
---From: <https://github.com/nvim-treesitter/nvim-treesitter/blob/cda8b291ef6fc4e04036e2ea6cf0de8aa84c2656/lua/nvim-treesitter/parsers.lua#L4-L23>.
153+
local filetype_to_parsername = {
154+
quarto = "markdown",
155+
}
156+
149157
local ft = {}
150158

151159
---Sets a commentstring(s) for a filetype/language
@@ -238,7 +246,9 @@ end
238246
---@see comment.utils.CommentCtx
239247
function ft.calculate(ctx)
240248
local buf = A.nvim_get_current_buf()
241-
local ok, parser = pcall(vim.treesitter.get_parser, buf)
249+
local filetype = vim.bo.filetype
250+
local parsername = filetype_to_parsername[filetype] or filetype
251+
local ok, parser = pcall(vim.treesitter.get_parser, buf, parsername)
242252

243253
if not ok then
244254
return ft.get(vim.bo.filetype, ctx.ctype) --[[ @as string ]]

0 commit comments

Comments
 (0)