@@ -158,7 +158,7 @@ function Handler:wiki_link(info)
158158 end
159159 local text = info .text :sub (2 , - 2 )
160160 local parts = str .split (text , ' |' )
161- local icon , highlight = self :destination_info (parts [1 ])
161+ local icon , highlight = self :dest_virt_text (parts [1 ])
162162 --- @type render.md.Mark
163163 return {
164164 conceal = true ,
@@ -178,26 +178,11 @@ end
178178--- @param info render.md.NodeInfo
179179--- @return render.md.Mark ?
180180function Handler :link (info )
181- local link = self .config .link
182181 -- Requires inline extmarks
183- if not link .enabled or not util .has_10 then
184- return nil
185- end
186- local icon , highlight
187- if info .type == ' inline_link' then
188- local destination = ts .child (self .buf , info , ' link_destination' )
189- if destination ~= nil then
190- icon , highlight = self :destination_info (destination .text )
191- else
192- icon , highlight = link .hyperlink , link .highlight
193- end
194- elseif info .type == ' full_reference_link' then
195- icon , highlight = link .hyperlink , link .highlight
196- elseif info .type == ' image' then
197- icon , highlight = link .image , link .highlight
198- else
182+ if not self .config .link .enabled or not util .has_10 then
199183 return nil
200184 end
185+ local icon , highlight = self :link_virt_text (info )
201186 context .get (self .buf ):add_link (info , icon )
202187 --- @type render.md.Mark
203188 return {
@@ -213,16 +198,33 @@ function Handler:link(info)
213198 }
214199end
215200
201+ --- @private
202+ --- @param info render.md.NodeInfo
203+ --- @return 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 == ' inline_link' then
209+ local destination = ts .child (self .buf , info , ' link_destination' )
210+ if destination ~= nil then
211+ return self :dest_virt_text (destination .text )
212+ end
213+ end
214+ return link .hyperlink , link .highlight
215+ end
216+
216217--- @private
217218--- @param destination string
218219--- @return string , string
219- function Handler :destination_info (destination )
220- local link_component = component . link ( self .config , destination )
221- if link_component == nil then
222- return self . config . link . hyperlink , self . config . link . highlight
223- else
224- return link_component . icon , link_component . highlight
220+ function Handler :dest_virt_text (destination )
221+ local link = self .config . link
222+ for _ , link_component in pairs ( link . custom ) do
223+ if destination : find ( link_component . pattern ) then
224+ return link_component . icon , link_component . highlight
225+ end
225226 end
227+ return link .hyperlink , link .highlight
226228end
227229
228230--- @class render.md.handler.MarkdownInline : render.md.Handler
0 commit comments