mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-02 11:36:54 -04:00
feat(markdown)!: switch to split parser (#3048)
* switch to split markdown parser with separate block and inline parsers to improve performance * add exclude_children! directive (useful for something like Injected markdown incorrectly highlights indented docstrings #2212) * split markdown queries into block and inline ones and add the injection for inline into block grammar * add include_dir option to parser configs (needed because the two grammars don't live in the repos root directory) BREAKING CHANGE: downstream queries need to be adapted to new parser
This commit is contained in:
parent
d810c38634
commit
002084b1be
7 changed files with 121 additions and 61 deletions
|
|
@ -128,3 +128,28 @@ query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
|
|||
metadata[key] = string.lower(text)
|
||||
end
|
||||
end)
|
||||
|
||||
query.add_directive("exclude_children!", function(match, _pattern, _bufnr, pred, metadata)
|
||||
local capture_id = pred[2]
|
||||
local node = match[capture_id]
|
||||
local start_row, start_col, end_row, end_col = node:range()
|
||||
local ranges = {}
|
||||
for i = 0, node:named_child_count() - 1 do
|
||||
local child = node:named_child(i)
|
||||
local child_start_row, child_start_col, child_end_row, child_end_col = child:range()
|
||||
if child_start_row > start_row or child_start_col > start_col then
|
||||
table.insert(ranges, {
|
||||
start_row,
|
||||
start_col,
|
||||
child_start_row,
|
||||
child_start_col,
|
||||
})
|
||||
end
|
||||
start_row = child_end_row
|
||||
start_col = child_end_col
|
||||
end
|
||||
if end_row > start_row or end_col > start_col then
|
||||
table.insert(ranges, { start_row, start_col, end_row, end_col })
|
||||
end
|
||||
metadata.content = ranges
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue