@@ -174,18 +174,104 @@ function OrgMarkup:get_prepared_headline_highlights(headline)
174
174
local result = {}
175
175
176
176
for type , highlight in pairs (highlights ) do
177
- vim .list_extend (
178
- result ,
179
- self .parsers [type ]:prepare_highlights (highlight , function (start_col , end_col )
180
- local text = headline .file :get_node_text (headline :node ())
181
- return text :sub (start_col , end_col )
182
- end )
183
- )
177
+ vim .list_extend (result , self .parsers [type ]:prepare_highlights (highlight ))
184
178
end
185
179
180
+ vim .list_extend (result , self :_prepare_ts_highlights (headline ))
181
+
186
182
return result
187
183
end
188
184
185
+ --- @private
186
+ --- @param headline OrgHeadline
187
+ --- @return OrgMarkupPreparedHighlight[]
188
+ function OrgMarkup :_prepare_ts_highlights (headline )
189
+ local headline_item_node = headline :node ():field (' item' )[1 ]
190
+ if not headline_item_node then
191
+ return {}
192
+ end
193
+ local result = {}
194
+ for node in headline_item_node :iter_children () do
195
+ if node :type () == ' link' or node :type () == ' link_desc' then
196
+ self :_prepare_link_higlight (headline , node , result )
197
+ end
198
+ if node :type () == ' timestamp' then
199
+ self :_prepare_date_highlight (node , result )
200
+ end
201
+ end
202
+ return result
203
+ end
204
+
205
+ --- @param headline OrgHeadline
206
+ --- @param node TSNode
207
+ --- @param result OrgMarkupPreparedHighlight[]
208
+ function OrgMarkup :_prepare_link_higlight (headline , node , result )
209
+ local url = node :field (' url' )[1 ]
210
+ local desc = node :field (' desc' )[1 ]
211
+ local url_target = nil
212
+
213
+ if desc then
214
+ local sld , scd , _ , ecd = desc :range ()
215
+ table.insert (result , {
216
+ start_line = sld ,
217
+ start_col = scd ,
218
+ end_col = ecd ,
219
+ hl_group = ' @org.hyperlink.desc' ,
220
+ })
221
+ table.insert (result , {
222
+ start_line = sld ,
223
+ start_col = scd - 2 ,
224
+ end_col = scd ,
225
+ conceal = ' ' ,
226
+ })
227
+ end
228
+
229
+ if url then
230
+ local slu , scu , _ , ecu = url :range ()
231
+ table.insert (result , {
232
+ start_line = slu ,
233
+ start_col = scu ,
234
+ end_col = ecu ,
235
+ hl_group = ' @org.hyperlink.url' ,
236
+ spell = false ,
237
+ conceal = desc and ' ' or nil ,
238
+ })
239
+ url_target = headline .file :get_node_text (url )
240
+ end
241
+ local sl , sc , _ , ec = node :range ()
242
+ table.insert (result , {
243
+ start_line = sl ,
244
+ start_col = sc ,
245
+ end_col = ec ,
246
+ hl_group = ' @org.hyperlink' ,
247
+ url = url_target ,
248
+ })
249
+ table.insert (result , {
250
+ start_line = sl ,
251
+ start_col = sc ,
252
+ end_col = sc + 2 ,
253
+ conceal = ' ' ,
254
+ })
255
+ table.insert (result , {
256
+ start_line = sl ,
257
+ start_col = ec - 2 ,
258
+ end_col = ec ,
259
+ conceal = ' ' ,
260
+ })
261
+ end
262
+
263
+ --- @param node TSNode
264
+ --- @param result OrgMarkupPreparedHighlight[]
265
+ function OrgMarkup :_prepare_date_highlight (node , result )
266
+ local sl , sc , _ , ec = node :range ()
267
+ table.insert (result , {
268
+ start_line = sl ,
269
+ start_col = sc ,
270
+ end_col = ec ,
271
+ hl_group = node :child (0 ):type () == ' <' and ' @org.timestamp.active' or ' @org.timestamp.inactive' ,
272
+ })
273
+ end
274
+
189
275
function OrgMarkup :on_detach (bufnr )
190
276
self .cache [bufnr ] = nil
191
277
end
0 commit comments