1- local Iter = require (' render-markdown.lib.iter' )
21local Str = require (' render-markdown.lib.str' )
32local colors = require (' render-markdown.colors' )
43
3130--- @param highlight ? string
3231function Base :sign (enabled , text , highlight )
3332 local sign = self .config .sign
34- if not enabled or not sign . enabled or not text then
33+ if not sign . enabled or not enabled or not text then
3534 return
3635 end
3736 local sign_highlight = sign .highlight
4948--- @param highlight string
5049--- @return boolean
5150function Base :check_icon (icon , highlight )
52- local line = self : append ({}, icon , highlight )
51+ local line = self . config : line (): text ( icon , highlight )
5352 local space = self .context :width (self .node ) + 1 - Str .width (icon )
5453 local right_pad = self .config .checkbox .right_pad
5554 if space < 0 then
5655 -- not enough space to fit the icon in-place
5756 return self .marks :over (' check_icon' , self .node , {
58- virt_text = self : append ( line , right_pad ),
57+ virt_text = line : pad ( right_pad ): get ( ),
5958 virt_text_pos = ' inline' ,
6059 conceal = ' ' ,
6160 }, { 0 , 0 , 0 , 1 })
6261 else
6362 local fits = math.min (space , right_pad )
64- self :append (line , fits )
6563 space = space - fits
6664 right_pad = right_pad - fits
6765 local row = self .node .start_row
6866 local start_col = self .node .start_col
6967 local end_col = self .node .end_col + 1
7068 self .marks :add (' check_icon' , row , start_col , {
7169 end_col = end_col - space ,
72- virt_text = line ,
70+ virt_text = line : pad ( fits ): get () ,
7371 virt_text_pos = ' overlay' ,
7472 })
7573 if space > 0 then
@@ -82,7 +80,7 @@ function Base:check_icon(icon, highlight)
8280 if right_pad > 0 then
8381 -- add padding
8482 self .marks :add (' check_icon' , row , end_col , {
85- virt_text = self : append ({}, right_pad ),
83+ virt_text = self . config : line (): pad ( right_pad ): get ( ),
8684 virt_text_pos = ' inline' ,
8785 })
8886 end
@@ -101,47 +99,26 @@ function Base:scope(element, node, highlight)
10199 self .marks :over (element , node :child (' inline' ), { hl_group = highlight })
102100end
103101
104- --- @protected
105- --- @param destination string
106- --- @param icon render.md.mark.Text
107- function Base :link_icon (destination , icon )
108- local options = Iter .table .filter (self .config .link .custom , function (custom )
109- if custom .kind == ' suffix' then
110- return vim .endswith (destination , custom .pattern )
111- else
112- return destination :find (custom .pattern ) ~= nil
113- end
114- end )
115- Iter .list .sort (options , function (custom )
116- return custom .priority or Str .width (custom .pattern )
117- end )
118- local result = options [# options ]
119- if result then
120- icon [1 ] = result .icon
121- icon [2 ] = result .highlight or icon [2 ]
122- end
123- end
124-
125102--- @protected
126103--- @param virtual boolean
127104--- @param level ? integer
128- --- @return render.md.mark. Line
105+ --- @return render.md.Line
129106function Base :indent_line (virtual , level )
130107 if virtual then
131108 level = self :indent_level (level )
132109 else
133110 assert (level , ' level must be known for real lines' )
134111 end
135- local line = {}
112+ local line = self . config : line ()
136113 if level > 0 then
137114 local indent = self .config .indent
138115 local icon_width = Str .width (indent .icon )
139116 if icon_width == 0 then
140- self : append ( line , indent .per_level * level )
117+ line : pad ( indent .per_level * level )
141118 else
142119 for _ = 1 , level do
143- self : append ( line , indent .icon , indent .highlight )
144- self : append ( line , indent .per_level - icon_width )
120+ line : text ( indent .icon , indent .highlight )
121+ line : pad ( indent .per_level - icon_width )
145122 end
146123 end
147124 end
@@ -177,23 +154,4 @@ function Base:indent_level(level)
177154 return math.max (level - indent .skip_level , 0 )
178155end
179156
180- --- @protected
181- --- @param line render.md.mark.Line
182- --- @param value string | integer
183- --- @param highlight ? string | string[]
184- --- @return render.md.mark.Line
185- function Base :append (line , value , highlight )
186- highlight = highlight or self .config .padding .highlight
187- if type (value ) == ' string' then
188- if # value > 0 then
189- line [# line + 1 ] = { value , highlight }
190- end
191- else
192- if value > 0 then
193- line [# line + 1 ] = { Str .pad (value ), highlight }
194- end
195- end
196- return line
197- end
198-
199157return Base
0 commit comments