1
+ local NodeInfo = require (' render-markdown.node_info' )
1
2
local code_block_parser = require (' render-markdown.parser.code_block' )
2
3
local colors = require (' render-markdown.colors' )
3
4
local component = require (' render-markdown.component' )
@@ -8,7 +9,6 @@ local logger = require('render-markdown.logger')
8
9
local pipe_table_parser = require (' render-markdown.parser.pipe_table' )
9
10
local state = require (' render-markdown.state' )
10
11
local str = require (' render-markdown.str' )
11
- local ts = require (' render-markdown.ts' )
12
12
13
13
--- @class render.md.handler.buf.Markdown
14
14
--- @field private buf integer
31
31
--- @return render.md.Mark[]
32
32
function Handler :parse (root )
33
33
context .get (self .buf ):query (root , state .markdown_query , function (capture , node )
34
- local info = ts . info ( node , self .buf )
34
+ local info = NodeInfo . new ( self .buf , node )
35
35
logger .debug_node_info (capture , info )
36
36
if capture == ' heading' then
37
37
self :heading (info )
@@ -46,8 +46,8 @@ function Handler:parse(root)
46
46
elseif capture == ' checkbox_checked' then
47
47
self :checkbox (info , self .config .checkbox .checked )
48
48
elseif capture == ' quote' then
49
- context .get (self .buf ):query (info . node , state .markdown_quote_query , function (nested_capture , nested_node )
50
- local nested_info = ts . info ( nested_node , self .buf )
49
+ context .get (self .buf ):query (node , state .markdown_quote_query , function (nested_capture , nested_node )
50
+ local nested_info = NodeInfo . new ( self .buf , nested_node )
51
51
logger .debug_node_info (nested_capture , nested_info )
52
52
if nested_capture == ' quote_marker' then
53
53
self :quote_marker (nested_info , info )
@@ -101,9 +101,9 @@ function Handler:heading(info)
101
101
if heading .width == ' block' then
102
102
-- Overwrite anything beyond left_pad + heading width + right_pad with Normal
103
103
local width = heading .left_pad + icon_width + heading .right_pad
104
- local content = ts . sibling (self . buf , info , ' inline' )
104
+ local content = info : sibling (' inline' )
105
105
if content ~= nil then
106
- width = width + str .width (content .text ) - ts . concealed (self . buf , content )
106
+ width = width + str .width (content .text ) - content : concealed ()
107
107
end
108
108
self :add (true , info .start_row , 0 , {
109
109
priority = 0 ,
@@ -134,7 +134,7 @@ function Handler:heading_icon(info, level, foreground, background)
134
134
-- Available width is level + 1 - concealed, where level = number of `#` characters, one
135
135
-- is added to account for the space after the last `#` but before the heading title,
136
136
-- and concealed text is subtracted since that space is not usable
137
- local width = level + 1 - ts . concealed (self . buf , info )
137
+ local width = level + 1 - info : concealed ()
138
138
if icon == nil then
139
139
return width
140
140
end
@@ -230,7 +230,7 @@ function Handler:language(code_block, add_background)
230
230
end
231
231
if code .position == ' left' then
232
232
local icon_text = icon .. ' '
233
- if ts . hidden (self . buf , info ) then
233
+ if info : hidden () then
234
234
-- Code blocks will pick up varying amounts of leading white space depending on the
235
235
-- context they are in. This gets lumped into the delimiter node and as a result,
236
236
-- after concealing, the extmark will be left shifted. Logic below accounts for this.
@@ -263,18 +263,14 @@ function Handler:code_background(code_block, icon_added)
263
263
264
264
if code .border == ' thin' then
265
265
local border_width = code_block .width - code_block .col
266
- if
267
- not icon_added
268
- and ts .hidden (self .buf , code_block .code_info )
269
- and ts .hidden (self .buf , code_block .start_delim )
270
- then
266
+ if not icon_added and code_block .code_info_hidden and code_block .start_delim_hidden then
271
267
self :add (true , code_block .start_row , code_block .col , {
272
268
virt_text = { { code .above :rep (border_width ), colors .inverse (code .highlight ) } },
273
269
virt_text_pos = ' overlay' ,
274
270
})
275
271
code_block .start_row = code_block .start_row + 1
276
272
end
277
- if ts . hidden ( self . buf , code_block .end_delim ) then
273
+ if code_block .end_delim_hidden then
278
274
self :add (true , code_block .end_row - 1 , code_block .col , {
279
275
virt_text = { { code .below :rep (border_width ), colors .inverse (code .highlight ) } },
280
276
virt_text_pos = ' overlay' ,
@@ -336,13 +332,13 @@ function Handler:list_marker(info)
336
332
if not self .config .checkbox .enabled then
337
333
return false
338
334
end
339
- if ts . sibling (self . buf , info , ' task_list_marker_unchecked' ) ~= nil then
335
+ if info : sibling (' task_list_marker_unchecked' ) ~= nil then
340
336
return true
341
337
end
342
- if ts . sibling (self . buf , info , ' task_list_marker_checked' ) ~= nil then
338
+ if info : sibling (' task_list_marker_checked' ) ~= nil then
343
339
return true
344
340
end
345
- local paragraph = ts . sibling (self . buf , info , ' paragraph' )
341
+ local paragraph = info : sibling (' paragraph' )
346
342
if paragraph == nil then
347
343
return false
348
344
end
@@ -360,7 +356,7 @@ function Handler:list_marker(info)
360
356
if not bullet .enabled then
361
357
return
362
358
end
363
- local level = ts . level_in_section (info , ' list' )
359
+ local level = info : level_in_section (' list' )
364
360
local icon = list .cycle (bullet .icons , level )
365
361
if icon == nil then
366
362
return
@@ -452,7 +448,7 @@ function Handler:pipe_table(info)
452
448
if not pipe_table .enabled or pipe_table .style == ' none' then
453
449
return
454
450
end
455
- local parsed_table = pipe_table_parser .parse (self . buf , info )
451
+ local parsed_table = pipe_table_parser .parse (info )
456
452
if parsed_table == nil then
457
453
return
458
454
end
512
508
function Handler :table_row (row , highlight )
513
509
local pipe_table = self .config .pipe_table
514
510
if vim .tbl_contains ({ ' raw' , ' padded' }, pipe_table .cell ) then
515
- for cell_node in row .node :iter_children () do
516
- local cell = ts .info (cell_node , self .buf )
511
+ row :for_each_child (function (cell )
517
512
if cell .type == ' |' then
518
513
self :add (true , cell .start_row , cell .start_col , {
519
514
end_row = cell .end_row ,
@@ -534,7 +529,7 @@ function Handler:table_row(row, highlight)
534
529
else
535
530
logger .unhandled_type (' markdown' , ' cell' , cell .type )
536
531
end
537
- end
532
+ end )
538
533
elseif pipe_table .cell == ' overlay' then
539
534
self :add (true , row .start_row , row .start_col , {
540
535
end_row = row .end_row ,
598
593
--- @param info render.md.NodeInfo
599
594
--- @return integer
600
595
function Handler :table_visual_offset (info )
601
- local result = ts . concealed (self . buf , info )
596
+ local result = info : concealed ()
602
597
local icon_ranges = context .get (self .buf ):get_links (info .start_row )
603
598
for _ , icon_range in ipairs (icon_ranges ) do
604
599
if info .start_col < icon_range [2 ] and info .end_col > icon_range [1 ] then
0 commit comments