@@ -21,8 +21,8 @@ function M.parse(root, buf)
2121 logger .debug_node_info (capture , info )
2222 if capture == ' code' then
2323 list .add_mark (marks , M .code (config , info ))
24- elseif capture == ' callout ' then
25- list .add_mark (marks , M .callout (config , buf , info ))
24+ elseif capture == ' shortcut ' then
25+ list .add_mark (marks , M .shortcut (config , buf , info ))
2626 elseif capture == ' link' then
2727 list .add_mark (marks , M .link (config , buf , info ))
2828 else
6262--- @param buf integer
6363--- @param info render.md.NodeInfo
6464--- @return render.md.Mark ?
65- function M .callout (config , buf , info )
65+ function M .shortcut (config , buf , info )
66+ local callout = component .callout (config , info .text , ' exact' )
67+ if callout ~= nil then
68+ return M .callout (config , buf , info , callout )
69+ end
70+ local checkbox = component .checkbox (config , info .text , ' exact' )
71+ if checkbox ~= nil then
72+ return M .checkbox (config , info , checkbox )
73+ end
74+ local line = vim .api .nvim_buf_get_lines (buf , info .start_row , info .start_row + 1 , true )[1 ]
75+ if line :find (' [' .. info .text .. ' ]' , 1 , true ) ~= nil then
76+ return M .wiki_link (config , info )
77+ end
78+ return nil
79+ end
80+
81+ --- @private
82+ --- @param config render.md.BufferConfig
83+ --- @param buf integer
84+ --- @param info render.md.NodeInfo
85+ --- @param callout render.md.CustomComponent
86+ --- @return render.md.Mark ?
87+ function M .callout (config , buf , info , callout )
6688 --- Support for overriding title: https://help.obsidian.md/Editing+and+formatting/Callouts#Change+the+title
67- --- @param callout render.md.CustomComponent
6889 --- @return string , string ?
69- local function custom_title (callout )
90+ local function custom_title ()
7091 local content = ts .parent (buf , info , ' inline' )
7192 if content ~= nil then
7293 local line = str .split (content .text , ' \n ' )[1 ]
@@ -79,51 +100,81 @@ function M.callout(config, buf, info)
79100 return callout .rendered , nil
80101 end
81102
82- local callout = component .callout (config , info .text , ' exact' )
83- if callout ~= nil then
84- if not config .quote .enabled then
85- return nil
86- end
87- local text , conceal = custom_title (callout )
88- --- @type render.md.Mark
89- return {
90- conceal = true ,
91- start_row = info .start_row ,
92- start_col = info .start_col ,
93- opts = {
94- end_row = info .end_row ,
95- end_col = info .end_col ,
96- virt_text = { { text , callout .highlight } },
97- virt_text_pos = ' overlay' ,
98- conceal = conceal ,
99- },
100- }
101- else
102- if not config .checkbox .enabled then
103- return nil
104- end
105- -- Requires inline extmarks
106- if not util .has_10 then
107- return nil
108- end
109- local checkbox = component .checkbox (config , info .text , ' exact' )
110- if checkbox == nil then
111- return nil
112- end
113- --- @type render.md.Mark
114- return {
115- conceal = true ,
116- start_row = info .start_row ,
117- start_col = info .start_col ,
118- opts = {
119- end_row = info .end_row ,
120- end_col = info .end_col ,
121- virt_text = { { str .pad_to (info .text , checkbox .rendered ), checkbox .highlight } },
122- virt_text_pos = ' inline' ,
123- conceal = ' ' ,
124- },
125- }
103+ if not config .quote .enabled then
104+ return nil
126105 end
106+ local text , conceal = custom_title ()
107+ --- @type render.md.Mark
108+ return {
109+ conceal = true ,
110+ start_row = info .start_row ,
111+ start_col = info .start_col ,
112+ opts = {
113+ end_row = info .end_row ,
114+ end_col = info .end_col ,
115+ virt_text = { { text , callout .highlight } },
116+ virt_text_pos = ' overlay' ,
117+ conceal = conceal ,
118+ },
119+ }
120+ end
121+
122+ --- @private
123+ --- @param config render.md.BufferConfig
124+ --- @param info render.md.NodeInfo
125+ --- @param checkbox render.md.CustomComponent
126+ --- @return render.md.Mark ?
127+ function M .checkbox (config , info , checkbox )
128+ if not config .checkbox .enabled then
129+ return nil
130+ end
131+ -- Requires inline extmarks
132+ if not util .has_10 then
133+ return nil
134+ end
135+ --- @type render.md.Mark
136+ return {
137+ conceal = true ,
138+ start_row = info .start_row ,
139+ start_col = info .start_col ,
140+ opts = {
141+ end_row = info .end_row ,
142+ end_col = info .end_col ,
143+ virt_text = { { str .pad_to (info .text , checkbox .rendered ), checkbox .highlight } },
144+ virt_text_pos = ' inline' ,
145+ conceal = ' ' ,
146+ },
147+ }
148+ end
149+
150+ --- @private
151+ --- @param config render.md.BufferConfig
152+ --- @param info render.md.NodeInfo
153+ --- @return render.md.Mark ?
154+ function M .wiki_link (config , info )
155+ local link = config .link
156+ if not link .enabled then
157+ return nil
158+ end
159+ -- Requires inline extmarks
160+ if not util .has_10 then
161+ return nil
162+ end
163+ local text = info .text :sub (2 , - 2 )
164+ local elements = str .split (text , ' |' )
165+ --- @type render.md.Mark
166+ return {
167+ conceal = true ,
168+ start_row = info .start_row ,
169+ start_col = info .start_col - 1 ,
170+ opts = {
171+ end_row = info .end_row ,
172+ end_col = info .end_col + 1 ,
173+ virt_text = { { link .hyperlink .. elements [# elements ], link .highlight } },
174+ virt_text_pos = ' inline' ,
175+ conceal = ' ' ,
176+ },
177+ }
127178end
128179
129180--- @private
@@ -158,7 +209,7 @@ function M.link(config, buf, info)
158209 opts = {
159210 end_row = info .end_row ,
160211 end_col = info .end_col ,
161- virt_text = { { icon , config . link .highlight } },
212+ virt_text = { { icon , link .highlight } },
162213 virt_text_pos = ' inline' ,
163214 },
164215 }
0 commit comments