1+ local Context = require (' render-markdown.context' )
12local NodeInfo = require (' render-markdown.node_info' )
23local code_block_parser = require (' render-markdown.parser.code_block' )
34local colors = require (' render-markdown.colors' )
45local component = require (' render-markdown.component' )
5- local context = require (' render-markdown.context' )
66local icons = require (' render-markdown.icons' )
77local list = require (' render-markdown.list' )
88local logger = require (' render-markdown.logger' )
@@ -13,6 +13,7 @@ local str = require('render-markdown.str')
1313--- @class render.md.handler.buf.Markdown
1414--- @field private buf integer
1515--- @field private config render.md.BufferConfig
16+ --- @field private context render.md.Context
1617--- @field private last_heading_border integer
1718--- @field private marks render.md.Mark[]
1819local Handler = {}
@@ -24,6 +25,7 @@ function Handler.new(buf)
2425 local self = setmetatable ({}, Handler )
2526 self .buf = buf
2627 self .config = state .get_config (buf )
28+ self .context = Context .get (buf )
2729 self .last_heading_border = - 1
2830 self .marks = {}
2931 return self
3234--- @param root TSNode
3335--- @return render.md.Mark[]
3436function Handler :parse (root )
35- context . get ( self .buf ) :query (root , state .markdown_query , function (capture , node )
37+ self .context :query (root , state .markdown_query , function (capture , node )
3638 local info = NodeInfo .new (self .buf , node )
3739 logger .debug_node_info (capture , info )
3840 if capture == ' heading' then
@@ -48,7 +50,7 @@ function Handler:parse(root)
4850 elseif capture == ' checkbox_checked' then
4951 self :checkbox (info , self .config .checkbox .checked )
5052 elseif capture == ' quote' then
51- context . get ( self .buf ) :query (node , state .markdown_quote_query , function (nested_capture , nested_node )
53+ self .context :query (node , state .markdown_quote_query , function (nested_capture , nested_node )
5254 local nested_info = NodeInfo .new (self .buf , nested_node )
5355 logger .debug_node_info (nested_capture , nested_info )
5456 if nested_capture == ' quote_marker' then
@@ -135,7 +137,7 @@ function Handler:heading_icon(info, level, foreground, background)
135137 -- Available width is level + 1 - concealed, where level = number of `#` characters, one
136138 -- is added to account for the space after the last `#` but before the heading title,
137139 -- and concealed text is subtracted since that space is not usable
138- local width = level + 1 - info :concealed ()
140+ local width = level + 1 - self . context :concealed (info )
139141 if icon == nil then
140142 return width
141143 end
@@ -171,11 +173,11 @@ function Handler:heading_width(info, icon_width)
171173 local width = heading .left_pad + icon_width + heading .right_pad
172174 local content = info :sibling (' inline' )
173175 if content ~= nil then
174- width = width + str .width (content .text ) + self : added_width (content ) - content :concealed ()
176+ width = width + str .width (content .text ) + self . context : link_width (content ) - self . context :concealed (content )
175177 end
176178 return math.max (width , heading .min_width )
177179 else
178- return context . get ( self .buf ) :get_width ()
180+ return self .context :get_width ()
179181 end
180182end
181183
@@ -234,7 +236,7 @@ function Handler:dash(info)
234236
235237 local width
236238 if dash .width == ' full' then
237- width = context . get ( self .buf ) :get_width ()
239+ width = self .context :get_width ()
238240 else
239241 --- @type integer
240242 width = dash .width
@@ -253,7 +255,7 @@ function Handler:code(info)
253255 if not code .enabled or code .style == ' none' then
254256 return
255257 end
256- local code_block = code_block_parser .parse (code , self .buf , info )
258+ local code_block = code_block_parser .parse (code , self .context , info )
257259 if code_block == nil then
258260 return
259261 end
@@ -294,7 +296,7 @@ function Handler:language(code_block, add_background)
294296 end
295297 if code .position == ' left' then
296298 local icon_text = icon .. ' '
297- if info :hidden () then
299+ if self . context :hidden (info ) then
298300 -- Code blocks will pick up varying amounts of leading white space depending on the
299301 -- context they are in. This gets lumped into the delimiter node and as a result,
300302 -- after concealing, the extmark will be left shifted. Logic below accounts for this.
657659--- @param info render.md.NodeInfo
658660--- @return integer
659661function Handler :table_visual_offset (info )
660- return info :concealed () - self :added_width (info )
661- end
662-
663- --- @private
664- --- @param info render.md.NodeInfo
665- --- @return integer
666- function Handler :added_width (info )
667- local result = 0
668- local icon_ranges = context .get (self .buf ):get_links (info .start_row )
669- for _ , icon_range in ipairs (icon_ranges ) do
670- if info .start_col < icon_range [2 ] and info .end_col > icon_range [1 ] then
671- result = result + str .width (icon_range [3 ])
672- end
673- end
674- return result
662+ return self .context :concealed (info ) - self .context :link_width (info )
675663end
676664
677665--- @class render.md.handler.Markdown : render.md.Handler
0 commit comments