Skip to content

Commit

Permalink
Use the current buffer parser and recurse all trees rather than parsi…
Browse files Browse the repository at this point in the history
…ng 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.
  • Loading branch information
MeanderingProgrammer committed Mar 23, 2024
1 parent fea6f3d commit e64255d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lua/render-markdown/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,19 @@ M.refresh = function()
return
end

local highlights = state.config.highlights
vim.treesitter.get_parser():for_each_tree(function(tree, language_tree)
local language = language_tree:lang()
if language == 'markdown' then
M.handle_markdown(tree)
end
end)
end

local root = vim.treesitter.get_parser(0, 'markdown'):parse()[1]:root()
---@param tree TSTree
M.handle_markdown = function(tree)
local highlights = state.config.highlights
---@diagnostic disable-next-line: missing-parameter
for id, node in state.config.query:iter_captures(root, 0) do
for id, node in state.config.query:iter_captures(tree:root(), 0) do
local capture = state.config.query.captures[id]
local value = vim.treesitter.get_node_text(node, 0)
local start_row, start_col, end_row, end_col = node:range()
Expand Down

0 comments on commit e64255d

Please # to comment.