@@ -109,18 +109,18 @@ function Handler:callout(info, callout)
109109 end
110110
111111 --- Support for overriding title: https://help.obsidian.md/Editing+and+formatting/Callouts#Change+the+title
112- --- @return string , string ?
112+ --- @return string , boolean
113113 local function custom_title ()
114114 local content = info :parent (' inline' )
115115 if content ~= nil then
116116 local line = str .split (content .text , ' \n ' )[1 ]
117117 if # line > # callout .raw and vim .startswith (line :lower (), callout .raw :lower ()) then
118118 local icon = str .split (callout .rendered , ' ' )[1 ]
119119 local title = vim .trim (line :sub (# callout .raw + 1 ))
120- return icon .. ' ' .. title , ' '
120+ return icon .. ' ' .. title , true
121121 end
122122 end
123- return callout .rendered , nil
123+ return callout .rendered , false
124124 end
125125
126126 local text , conceal = custom_title ()
@@ -129,7 +129,7 @@ function Handler:callout(info, callout)
129129 end_col = info .end_col ,
130130 virt_text = { { text , callout .highlight } },
131131 virt_text_pos = ' overlay' ,
132- conceal = conceal ,
132+ conceal = conceal and ' ' or nil ,
133133 })
134134 if added then
135135 self .context :add_component (info , callout )
@@ -160,12 +160,18 @@ end
160160--- @private
161161--- @param info render.md.NodeInfo
162162function Handler :wiki_link (info )
163- if not self .config .link .enabled then
163+ local link = self .config .link
164+ if not link .enabled then
164165 return
165166 end
166- local text = info .text :sub (2 , - 2 )
167- local parts = str .split (text , ' |' )
168- local icon , highlight = self :dest_virt_text (parts [1 ])
167+
168+ local parts = str .split (info .text :sub (2 , - 2 ), ' |' )
169+ local link_component = self :link_component (parts [1 ])
170+
171+ local icon , highlight = link .hyperlink , link .highlight
172+ if link_component ~= nil then
173+ icon , highlight = link_component .icon , link_component .highlight
174+ end
169175 local link_text = icon .. parts [# parts ]
170176 local added = self .marks :add (true , info .start_row , info .start_col - 1 , {
171177 end_row = info .end_row ,
@@ -182,60 +188,56 @@ end
182188--- @private
183189--- @param info render.md.NodeInfo
184190function Handler :link (info )
185- if not self .config .link .enabled then
191+ local link = self .config .link
192+ if not link .enabled then
186193 return
187194 end
188- local link_text , highlight , conceal = self :link_virt_text (info )
189- local added = self .marks :add (true , info .start_row , info .start_col , {
190- end_row = info .end_row ,
191- end_col = info .end_col ,
192- virt_text = { { link_text , highlight } },
193- virt_text_pos = ' inline' ,
194- conceal = conceal ,
195- })
196- if conceal == nil and added then
197- self .context :add_offset (info , str .width (link_text ))
198- end
199- end
200195
201- --- @private
202- --- @param info render.md.NodeInfo
203- --- @return string , string , string ?
204- function Handler :link_virt_text (info )
205- local link = self .config .link
206- if info .type == ' image' then
207- return link .image , link .highlight
208- elseif info .type == ' email_autolink' then
209- return link .email .. info .text :sub (2 , - 2 ), link .highlight , ' '
210- elseif info .type == ' inline_link' then
211- local destination = info :child (' link_destination' )
212- if destination ~= nil then
213- return self :dest_virt_text (destination .text )
196+ if info .type == ' email_autolink' then
197+ local link_text = link .email .. info .text :sub (2 , - 2 )
198+ self .marks :add (true , info .start_row , info .start_col , {
199+ end_row = info .end_row ,
200+ end_col = info .end_col ,
201+ virt_text = { { link_text , link .highlight } },
202+ virt_text_pos = ' inline' ,
203+ conceal = ' ' ,
204+ })
205+ else
206+ local link_text , highlight = link .hyperlink , link .highlight
207+ if info .type == ' image' then
208+ link_text = link .image
209+ elseif info .type == ' inline_link' then
210+ local destination = info :child (' link_destination' )
211+ local link_component = destination ~= nil and self :link_component (destination .text ) or nil
212+ if link_component ~= nil then
213+ link_text , highlight = link_component .icon , link_component .highlight
214+ end
215+ end
216+
217+ local added = self .marks :add (true , info .start_row , info .start_col , {
218+ end_row = info .end_row ,
219+ end_col = info .end_col ,
220+ virt_text = { { link_text , highlight } },
221+ virt_text_pos = ' inline' ,
222+ })
223+ if added then
224+ self .context :add_offset (info , str .width (link_text ))
214225 end
215226 end
216- return link .hyperlink , link .highlight
217227end
218228
219229--- @private
220230--- @param destination string
221- --- @return string , string
222- function Handler :dest_virt_text (destination )
223- local link = self .config .link
224-
231+ --- @return render.md.LinkComponent ?
232+ function Handler :link_component (destination )
225233 --- @type render.md.LinkComponent[]
226234 local link_components = vim .tbl_filter (function (link_component )
227235 return destination :find (link_component .pattern ) ~= nil
228- end , link .custom )
236+ end , self . config . link .custom )
229237 table.sort (link_components , function (a , b )
230238 return str .width (a .pattern ) < str .width (b .pattern )
231239 end )
232-
233- if # link_components > 0 then
234- local link_component = link_components [# link_components ]
235- return link_component .icon , link_component .highlight
236- else
237- return link .hyperlink , link .highlight
238- end
240+ return link_components [# link_components ]
239241end
240242
241243--- @class render.md.handler.MarkdownInline : render.md.Handler
0 commit comments