1
+ local list = require (' markdown.list' )
1
2
local state = require (' markdown.state' )
2
3
3
4
local M = {}
@@ -6,17 +7,22 @@ local M = {}
6
7
--- @field public head ? string
7
8
--- @field public row ? string
8
9
10
+ --- @class UserHeadingHighlights
11
+ --- @field public backgrounds ? string[]
12
+ --- @field public foregrounds ? string[]
13
+
9
14
--- @class UserHighlights
10
- --- @field public heading ? string
15
+ --- @field public heading ? UserHeadingHighlights
11
16
--- @field public code ? string
12
17
--- @field public bullet ? string
13
18
--- @field public table ? UserTableHighlights
14
19
15
20
--- @class UserConfig
16
21
--- @field public query ? Query
17
22
--- @field public render_modes ? string[]
23
+ --- @field public headings ? string[]
18
24
--- @field public bullet ? string
19
- --- @field public highlights ? Highlights
25
+ --- @field public highlights ? UserHighlights
20
26
21
27
--- @param opts UserConfig | nil
22
28
function M .setup (opts )
@@ -44,9 +50,20 @@ function M.setup(opts)
44
50
]]
45
51
),
46
52
render_modes = { ' n' , ' c' },
53
+ headings = { ' ◉' , ' ○' , ' ✸' , ' ✿' },
47
54
bullet = ' ○' ,
48
55
highlights = {
49
- headings = { ' DiffAdd' , ' DiffChange' , ' DiffDelete' },
56
+ heading = {
57
+ backgrounds = { ' DiffAdd' , ' DiffChange' , ' DiffDelete' },
58
+ foregrounds = {
59
+ ' markdownH1' ,
60
+ ' markdownH2' ,
61
+ ' markdownH3' ,
62
+ ' markdownH4' ,
63
+ ' markdownH5' ,
64
+ ' markdownH6' ,
65
+ },
66
+ },
50
67
code = ' ColorColumn' ,
51
68
bullet = ' Normal' ,
52
69
table = {
@@ -94,15 +111,23 @@ M.refresh = function()
94
111
--- @diagnostic disable-next-line : missing-parameter
95
112
for id , node in state .config .query :iter_captures (root , 0 ) do
96
113
local capture = state .config .query .captures [id ]
114
+ local value = vim .treesitter .get_node_text (node , 0 )
97
115
local start_row , start_col , end_row , end_col = node :range ()
98
116
99
117
if capture == ' heading' then
100
- local level = # vim .treesitter .get_node_text (node , 0 )
101
- local highlight = highlights .headings [((level - 1 ) % # highlights .headings ) + 1 ]
118
+ local level = # value
119
+ local heading = list .cycle (state .config .headings , level )
120
+ local background = list .clamp_last (highlights .heading .backgrounds , level )
121
+ local foreground = list .clamp_last (highlights .heading .foregrounds , level )
122
+
123
+ local virt_text = { string.rep (' ' , level - 1 ) .. heading , { foreground , background } }
102
124
vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , 0 , {
103
125
end_row = end_row + 1 ,
104
126
end_col = 0 ,
105
- hl_group = highlight ,
127
+ hl_group = background ,
128
+ virt_text = { virt_text },
129
+ virt_text_pos = ' overlay' ,
130
+ hl_eol = true ,
106
131
})
107
132
elseif capture == ' code' then
108
133
vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , 0 , {
@@ -112,19 +137,18 @@ M.refresh = function()
112
137
hl_eol = true ,
113
138
})
114
139
elseif capture == ' item' then
140
+ local virt_text = { state .config .bullet , highlights .bullet }
115
141
vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , start_col , {
116
142
end_row = end_row ,
117
143
end_col = end_col ,
118
- virt_text = { { state . config . bullet , highlights . bullet } },
144
+ virt_text = { virt_text },
119
145
virt_text_pos = ' overlay' ,
120
146
})
121
147
elseif vim .tbl_contains ({ ' table_head' , ' table_delim' , ' table_row' }, capture ) then
122
- local row = vim .treesitter .get_node_text (node , 0 )
123
- local modified_row = row :gsub (' |' , ' │' )
148
+ local row = value :gsub (' |' , ' │' )
124
149
if capture == ' table_delim' then
125
150
-- Order matters here, in particular handling inner intersections before left & right
126
- modified_row = modified_row
127
- :gsub (' -' , ' ─' )
151
+ row = row :gsub (' -' , ' ─' )
128
152
:gsub (' ' , ' ─' )
129
153
:gsub (' ─│─' , ' ─┼─' )
130
154
:gsub (' │─' , ' ├─' )
@@ -136,10 +160,11 @@ M.refresh = function()
136
160
highlight = highlights .table .row
137
161
end
138
162
163
+ local virt_text = { row , highlight }
139
164
vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , start_col , {
140
165
end_row = end_row ,
141
166
end_col = end_col ,
142
- virt_text = { { modified_row , highlight } },
167
+ virt_text = { virt_text },
143
168
virt_text_pos = ' overlay' ,
144
169
})
145
170
else
0 commit comments