Skip to content

Commit 366da77

Browse files
Add bullet point replacement to rendered view, fill out some other features
1 parent 3fd818c commit 366da77

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Plugin to improve viewing Markdown files in Neovim
44

55
# Features
66

7-
TODO
7+
- Changes between `rendered` view in normal mode (exact modes are configurable)
8+
and raw view in all other modes
9+
- Highlights headings with different groups depending on level
10+
- Highlights code blocks to better stand out
11+
- Replaces whichever style bullet point is being used with provided character
812

913
# Dependencies
1014

@@ -37,13 +41,16 @@ WIP
3741
] @heading)
3842
3943
(fenced_code_block) @code
44+
45+
(list_item) @item
4046
]]
4147
),
4248
render_modes = { 'n', 'c' },
43-
bullets = { '', '', '', '' },
49+
bullet = '',
4450
highlights = {
4551
headings = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
4652
code = 'ColorColumn',
53+
bullet = 'Normal',
4754
},
4855
})
4956
end,

lua/markdown/init.lua

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ local M = {}
55
---@class UserHighlights
66
---@field public heading? string
77
---@field public code? string
8+
---@field public bullet? string
89

910
---@class UserConfig
1011
---@field public query? Query
1112
---@field public render_modes? string[]
12-
---@field public bullets? string[]
13+
---@field public bullet? string
1314
---@field public highlights? Highlights
1415

1516
---@param opts UserConfig|nil
@@ -28,11 +29,6 @@ function M.setup(opts)
2829
MatchParen bg = 1f2e3f (deep blue) fg = 31748f (teel)
2930
]]
3031

31-
-- Some attempts to handle nested lists
32-
-- (list_item) @item1
33-
-- (list_item (list_item (list_item))) @item3
34-
-- (list) @item1
35-
3632
---@type Config
3733
local default_config = {
3834
query = vim.treesitter.query.parse(
@@ -48,13 +44,16 @@ function M.setup(opts)
4844
] @heading)
4945
5046
(fenced_code_block) @code
47+
48+
(list_item) @item
5149
]]
5250
),
5351
render_modes = { 'n', 'c' },
54-
bullets = { '', '', '', '' },
52+
bullet = '',
5553
highlights = {
5654
headings = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
5755
code = 'ColorColumn',
56+
bullet = 'Normal',
5857
},
5958
}
6059
state.config = vim.tbl_deep_extend('force', default_config, opts or {})
@@ -98,7 +97,7 @@ M.refresh = function()
9897
---@diagnostic disable-next-line: missing-parameter
9998
for id, node in state.config.query:iter_captures(root, 0) do
10099
local capture = state.config.query.captures[id]
101-
local start_row, _, end_row, _ = node:range()
100+
local start_row, start_col, end_row, end_col = node:range()
102101

103102
if capture == 'heading' then
104103
local level = #vim.treesitter.get_node_text(node, 0)
@@ -115,9 +114,16 @@ M.refresh = function()
115114
hl_group = highlights.code,
116115
hl_eol = true,
117116
})
117+
elseif capture == 'item' then
118+
vim.api.nvim_buf_set_extmark(0, M.namespace, start_row, start_col, {
119+
end_row = end_row,
120+
end_col = end_col,
121+
virt_text = { { state.config.bullet, highlights.bullet } },
122+
virt_text_pos = 'overlay',
123+
})
118124
else
119-
vim.print('Unknown capture: ' .. capture)
120-
vim.print(vim.treesitter.get_node_text(node, 0))
125+
-- Should only get here if user provides custom capture, currently unhandled
126+
vim.print('Unhandled capture: ' .. capture)
121127
end
122128
end
123129
end

lua/markdown/state.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---@class Highlights
22
---@field public headings string[]
33
---@field public code string
4+
---@field public bullet string
45

56
---@class Config
67
---@field public query Query
78
---@field public render_modes string[]
8-
---@field public bullets string[]
9+
---@field public bullet string
910
---@field public highlights Highlights
1011

1112
---@class State

0 commit comments

Comments
 (0)