diff --git a/README.md b/README.md index 5610de8..3c3d337 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ require('render-markdown').setup({ render_modes = { 'n', 'c' }, -- Characters that will replace the # at the start of headings headings = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' }, - -- Character to use for the bullet point in lists - bullet = '○', + -- Character to use for the bullet points in lists + bullets = {"●","○","◆","◇"}, -- Character that will replace the > at the start of block quotes quote = '┃', -- See :h 'conceallevel' for more information about meaning of values diff --git a/doc/render-markdown.txt b/doc/render-markdown.txt index bdfdd11..da4c052 100644 --- a/doc/render-markdown.txt +++ b/doc/render-markdown.txt @@ -112,8 +112,8 @@ modified by the user. render_modes = { 'n', 'c' }, -- Characters that will replace the # at the start of headings headings = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' }, - -- Character to use for the bullet point in lists - bullet = '○', + -- Character to use for the bullet points in lists + bullets = {"●","○","◆","◇"}, -- Character that will replace the > at the start of block quotes quote = '┃', -- See :h 'conceallevel' for more information about meaning of values diff --git a/lua/render-markdown/init.lua b/lua/render-markdown/init.lua index f58144c..aeb5b84 100644 --- a/lua/render-markdown/init.lua +++ b/lua/render-markdown/init.lua @@ -29,7 +29,7 @@ local M = {} ---@field public file_types? string[] ---@field public render_modes? string[] ---@field public headings? string[] ----@field public bullet? string +---@field public bullets? string[] ---@field public quote? string ---@field public conceal? UserConceal ---@field public fat_tables? boolean @@ -71,7 +71,7 @@ function M.setup(opts) file_types = { 'markdown' }, render_modes = { 'n', 'c' }, headings = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' }, - bullet = '○', + bullets = {"●","○","◆","◇"}, quote = '┃', conceal = { default = vim.opt.conceallevel:get(), diff --git a/lua/render-markdown/state.lua b/lua/render-markdown/state.lua index ae06e1a..fa51dea 100644 --- a/lua/render-markdown/state.lua +++ b/lua/render-markdown/state.lua @@ -24,7 +24,7 @@ ---@field public file_types string[] ---@field public render_modes string[] ---@field public headings string[] ----@field public bullet string +---@field public bullets string[] ---@field public quote string ---@field public conceal Conceal ---@field public fat_tables boolean diff --git a/lua/render-markdown/ui.lua b/lua/render-markdown/ui.lua index 4985297..3b5675c 100644 --- a/lua/render-markdown/ui.lua +++ b/lua/render-markdown/ui.lua @@ -37,6 +37,28 @@ M.refresh = function() end) end +--- Walk through all parent nodes and count the number of nodes with type list +--- to calculate the level of the given node +---@param node TSNode +---@return integer +M.calculate_list_level = function(node) + local candidate = node:parent() + local level = 0 + while candidate ~= nil do + local candidate_type = candidate:type() + if candidate_type == "section" or candidate_type == "document" then + -- when reaching a section or the document we are clearly at the + -- top of the list + break + elseif candidate_type == "list" then + -- found a list increase the level and continue + level = level + 1 + end + candidate = candidate:parent() + end + return level +end + ---@param root TSNode M.markdown = function(root) local highlights = state.config.highlights @@ -73,7 +95,10 @@ M.markdown = function(root) -- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127 -- As a result we handle leading spaces here, can remove if this gets fixed upstream local _, leading_spaces = value:find('^%s*') - local virt_text = { string.rep(' ', leading_spaces or 0) .. state.config.bullet, highlights.bullet } + -- Get the level of the list_marker by counting the number of parent list nodes + local level = M.calculate_list_level(node) + local bullet_marker = list.cycle(state.config.bullets, level) + local virt_text = { string.rep(' ', leading_spaces or 0) .. bullet_marker, highlights.bullet } vim.api.nvim_buf_set_extmark(0, M.namespace, start_row, start_col, { end_row = end_row, end_col = end_col,