@@ -1038,7 +1038,7 @@ end
10381038--- Render ==tag==.
10391039--- @param buffer integer
10401040--- @param item markview.parsed.markdown_inline.tags
1041- inline .tag = function (buffer , item )
1041+ inline .tag = function (buffer , item , heading_lines )
10421042 --- @type markview.config.markdown_inline.tags ?
10431043 local main_config = spec .get ({ " markdown_inline" , " tags" }, { fallback = nil });
10441044 local range = item .range ;
@@ -1084,11 +1084,40 @@ inline.tag = function (buffer, item)
10841084 -- hl_mode = "combine"
10851085 });
10861086
1087- vim .api .nvim_buf_set_extmark (buffer , inline .ns , range .row_start , range .col_start + 1 , {
1088- undo_restore = false , invalidate = true ,
1089- end_col = range .col_end ,
1090- hl_group = utils .set_hl (config .hl )
1091- });
1087+ if heading_lines [range .row_start ] or config .virtual then
1088+ local text = item .text [1 ] or " " ;
1089+
1090+ text = string.gsub (text , " ^`+" , " " );
1091+ text = string.gsub (text , " `+$" , " " );
1092+
1093+ local chars = vim .fn .split (text , " \\ zs" );
1094+ local col_offset = 0 ;
1095+
1096+ --[[
1097+ NOTE: Virtual texts do not wrap with the text.
1098+
1099+ So, the text is split into characters and each character gets a mask applied to it.
1100+ ]]
1101+ for c = 2 , # chars do
1102+ vim .api .nvim_buf_set_extmark (buffer , inline .ns , range .row_start , (range .col_start + 1 ) + col_offset , {
1103+ undo_restore = false , invalidate = true ,
1104+
1105+ virt_text_pos = " overlay" ,
1106+ virt_text = {
1107+ { chars [c ], utils .set_hl (config .hl ) }
1108+ }
1109+ });
1110+
1111+ col_offset = col_offset + # chars [c ];
1112+ end
1113+ else
1114+ vim .api .nvim_buf_set_extmark (buffer , inline .ns , range .row_start , range .col_start + 1 , {
1115+ undo_restore = false , invalidate = true ,
1116+ end_row = range .row_end ,
1117+ end_col = range .col_end ,
1118+ hl_group = utils .set_hl (config .hl )
1119+ });
1120+ end
10921121
10931122 vim .api .nvim_buf_set_extmark (buffer , inline .ns , range .row_start , range .col_end , {
10941123 undo_restore = false , invalidate = true ,
0 commit comments