Skip to content

Commit e64255d

Browse files
Use the current buffer parser and recurse all trees rather than parsing buffer as markdown
## Details This should solve issue: #3 This will allow for markdown to be rendered with this plugin when injected in other languages, for example Python comments. Currently we attempt to parse the entire buffer as markdown which leads to some strange behavior, i.e. interpretting single line comments as markdown. After this change we will read the injected markdown sections. This should also allow us to take advantage of the markdown_inline parser for later changes, which is nice.
1 parent fea6f3d commit e64255d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: lua/render-markdown/init.lua

+11-3
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,19 @@ M.refresh = function()
131131
return
132132
end
133133

134-
local highlights = state.config.highlights
134+
vim.treesitter.get_parser():for_each_tree(function(tree, language_tree)
135+
local language = language_tree:lang()
136+
if language == 'markdown' then
137+
M.handle_markdown(tree)
138+
end
139+
end)
140+
end
135141

136-
local root = vim.treesitter.get_parser(0, 'markdown'):parse()[1]:root()
142+
---@param tree TSTree
143+
M.handle_markdown = function(tree)
144+
local highlights = state.config.highlights
137145
---@diagnostic disable-next-line: missing-parameter
138-
for id, node in state.config.query:iter_captures(root, 0) do
146+
for id, node in state.config.query:iter_captures(tree:root(), 0) do
139147
local capture = state.config.query.captures[id]
140148
local value = vim.treesitter.get_node_text(node, 0)
141149
local start_row, start_col, end_row, end_col = node:range()

0 commit comments

Comments
 (0)