Skip to content

Commit b41bce8

Browse files
Extended the functionalities to +, and * for lists.
1 parent ebd69b5 commit b41bce8

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

lua/render-markdown/integ/source.lua

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@ local manager = require('render-markdown.manager')
22
local state = require('render-markdown.state')
33
local util = require('render-markdown.core.util')
44

5+
local function get_list_prefix(buf, row)
6+
local line = vim.fn.getline(row + 1) -- Get the current line (rows are 1-indexed in Vim)
7+
local prev_line = vim.fn.getline(row)
8+
local first_non_white = string.match(line, '^%s*(.)') -- Find first non-white character
9+
-- List of possible markers to check
10+
11+
local first_non_white_prev = string.match(prev_line, '^%s*(.)')
12+
local list_prefix = ''
13+
local markers = { '-', '*', '+' }
14+
if vim.tbl_contains(markers, first_non_white) or first_non_white == '[' then
15+
list_prefix = ''
16+
else
17+
for _, marker in ipairs(markers) do
18+
if first_non_white_prev == marker then
19+
-- Set the list prefix based on the matched marker
20+
list_prefix = marker .. ' '
21+
break
22+
end
23+
end
24+
end
25+
return list_prefix
26+
end
27+
528
---@class render.md.Source
629
local M = {}
730

@@ -35,16 +58,9 @@ function M.items(buf, row, col)
3558
table.insert(items, M.item(component.raw, component.rendered, nil))
3659
end
3760
elseif vim.tbl_contains({ 'list_item', 'list_marker_minus' }, node_type) then
38-
local line = vim.fn.getline(row + 1) -- Get the current line (rows are 1-indexed in Vim)
39-
local first_non_white = string.match(line, '^%s*(.)') -- Find first non-white character
40-
local list_prefix = '- '
41-
-- Check if the first non-white character is a '-'
42-
if first_non_white == '-' then
43-
list_prefix = ''
44-
end
45-
4661
local checkbox = config.checkbox
4762

63+
local list_prefix = get_list_prefix(buf, row)
4864
table.insert(
4965
items,
5066
M.item(list_prefix .. (checkbox.unchecked.raw or '[ ]'), checkbox.unchecked.icon, 'unchecked')

0 commit comments

Comments
 (0)