@@ -2,10 +2,15 @@ local state = require('markdown.state')
2
2
3
3
local M = {}
4
4
5
+ --- @class UserTableHighlights
6
+ --- @field public head ? string
7
+ --- @field public row ? string
8
+
5
9
--- @class UserHighlights
6
10
--- @field public heading ? string
7
11
--- @field public code ? string
8
12
--- @field public bullet ? string
13
+ --- @field public table ? UserTableHighlights
9
14
10
15
--- @class UserConfig
11
16
--- @field public query ? Query
@@ -15,20 +20,6 @@ local M = {}
15
20
16
21
--- @param opts UserConfig | nil
17
22
function M .setup (opts )
18
- --[[
19
- Reference for pre-defined highlight groups and colors
20
- ColorColumn bg = 1f1d2e (dark gray / purple)
21
- PmenuExtra bg = 1f1d2e (dark gray / purple) fg = 6e6a86 (light purple)
22
- CursorColumn bg = 26233a (more purple version of 1f1d2e)
23
- PmenuSel bg = 26233a (more purple version of 1f1d2e) fg = e0def4 (white / pink)
24
- CurSearch bg = f6c177 (light orange) fg = 191724 (dark gray)
25
- DiffAdd bg = 333c48 (gray / little bit blue)
26
- DiffChange bg = 433842 (pink / gray)
27
- DiffDelete bg = 43293a (darker version of 433842)
28
- Visual bg = 403d52 (lighter version of 1f1d2e)
29
- MatchParen bg = 1f2e3f (deep blue) fg = 31748f (teel)
30
- ]]
31
-
32
23
--- @type Config
33
24
local default_config = {
34
25
query = vim .treesitter .query .parse (
@@ -46,6 +37,10 @@ function M.setup(opts)
46
37
(fenced_code_block) @code
47
38
48
39
(list_item) @item
40
+
41
+ (pipe_table_header) @table_head
42
+ (pipe_table_delimiter_row) @table_delim
43
+ (pipe_table_row) @table_row
49
44
]]
50
45
),
51
46
render_modes = { ' n' , ' c' },
@@ -54,6 +49,10 @@ function M.setup(opts)
54
49
headings = { ' DiffAdd' , ' DiffChange' , ' DiffDelete' },
55
50
code = ' ColorColumn' ,
56
51
bullet = ' Normal' ,
52
+ table = {
53
+ head = ' @markup.heading' ,
54
+ row = ' Normal' ,
55
+ },
57
56
},
58
57
}
59
58
state .config = vim .tbl_deep_extend (' force' , default_config , opts or {})
@@ -119,6 +118,30 @@ M.refresh = function()
119
118
virt_text = { { state .config .bullet , highlights .bullet } },
120
119
virt_text_pos = ' overlay' ,
121
120
})
121
+ 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 (' |' , ' │' )
124
+ if capture == ' table_delim' then
125
+ -- Order matters here, in particular handling inner intersections before left & right
126
+ modified_row = modified_row
127
+ :gsub (' -' , ' ─' )
128
+ :gsub (' ' , ' ─' )
129
+ :gsub (' ─│─' , ' ─┼─' )
130
+ :gsub (' │─' , ' ├─' )
131
+ :gsub (' ─│' , ' ─┤' )
132
+ end
133
+
134
+ local highlight = highlights .table .head
135
+ if capture == ' table_row' then
136
+ highlight = highlights .table .row
137
+ end
138
+
139
+ vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , start_col , {
140
+ end_row = end_row ,
141
+ end_col = end_col ,
142
+ virt_text = { { modified_row , highlight } },
143
+ virt_text_pos = ' overlay' ,
144
+ })
122
145
else
123
146
-- Should only get here if user provides custom capture, currently unhandled
124
147
vim .print (' Unhandled capture: ' .. capture )
0 commit comments