@@ -2,10 +2,15 @@ local state = require('markdown.state')
22
33local M = {}
44
5+ --- @class UserTableHighlights
6+ --- @field public head ? string
7+ --- @field public row ? string
8+
59--- @class UserHighlights
610--- @field public heading ? string
711--- @field public code ? string
812--- @field public bullet ? string
13+ --- @field public table ? UserTableHighlights
914
1015--- @class UserConfig
1116--- @field public query ? Query
@@ -15,20 +20,6 @@ local M = {}
1520
1621--- @param opts UserConfig | nil
1722function 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-
3223 --- @type Config
3324 local default_config = {
3425 query = vim .treesitter .query .parse (
@@ -46,6 +37,10 @@ function M.setup(opts)
4637 (fenced_code_block) @code
4738
4839 (list_item) @item
40+
41+ (pipe_table_header) @table_head
42+ (pipe_table_delimiter_row) @table_delim
43+ (pipe_table_row) @table_row
4944 ]]
5045 ),
5146 render_modes = { ' n' , ' c' },
@@ -54,6 +49,10 @@ function M.setup(opts)
5449 headings = { ' DiffAdd' , ' DiffChange' , ' DiffDelete' },
5550 code = ' ColorColumn' ,
5651 bullet = ' Normal' ,
52+ table = {
53+ head = ' @markup.heading' ,
54+ row = ' Normal' ,
55+ },
5756 },
5857 }
5958 state .config = vim .tbl_deep_extend (' force' , default_config , opts or {})
@@ -119,6 +118,30 @@ M.refresh = function()
119118 virt_text = { { state .config .bullet , highlights .bullet } },
120119 virt_text_pos = ' overlay' ,
121120 })
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+ })
122145 else
123146 -- Should only get here if user provides custom capture, currently unhandled
124147 vim .print (' Unhandled capture: ' .. capture )
0 commit comments