Skip to content

Commit a296d0b

Browse files
Apply stylua / minor edits / demo update
1 parent fdd774e commit a296d0b

File tree

6 files changed

+36
-33
lines changed

6 files changed

+36
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Plugin to improve viewing Markdown files in Neovim
1212
- Supports rendering `markdown` injected into other file types
1313
- Highlights headings with different groups depending on level and replaces `#`
1414
- Highlights code blocks and inline code to better stand out
15-
- Replaces whichever style bullet point is being used with provided character
15+
- Replaces bullet points with provided character based on level
1616
- Replaces block quote leading `>` with provided character
1717
- Updates table borders with better border characters, does NOT automatically align
1818
- Basic support for `LaTeX` if `pylatexenc` is installed on system
@@ -86,7 +86,7 @@ require('render-markdown').setup({
8686
-- Characters that will replace the # at the start of headings
8787
headings = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
8888
-- Character to use for the bullet points in lists
89-
bullets = {"","","",""},
89+
bullets = { '', '', '', '' },
9090
-- Character that will replace the > at the start of block quotes
9191
quote = '',
9292
-- See :h 'conceallevel' for more information about meaning of values

demo/demo.gif

8.27 KB
Loading

demo/sample.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ if __name__ == "__main__":
2222

2323
- List Item 1: with [link](https://example.com)
2424
* List Item 2: with `inline` code
25-
* Nested List Item 1
26-
* Nested List Item 2
25+
* Nested List 1 Item 1
26+
* Nested List 1 Item 2
27+
- Nested List 2 Item 1
28+
- Nested List 3 Item 1
29+
- Nested List 4 Item 1
2730
+ List Item 3
2831

2932
1. Item 1

doc/render-markdown.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.9.5 Last change: 2024 March 29
1+
*render-markdown.txt* For 0.9.5 Last change: 2024 April 01
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -32,7 +32,7 @@ Plugin to improve viewing Markdown files in Neovim
3232
- Supports rendering `markdown` injected into other file types
3333
- Highlights headings with different groups depending on level and replaces `#`
3434
- Highlights code blocks and inline code to better stand out
35-
- Replaces whichever style bullet point is being used with provided character
35+
- Replaces bullet points with provided character based on level
3636
- Replaces block quote leading `>` with provided character
3737
- Updates table borders with better border characters, does NOT automatically align
3838
- Basic support for `LaTeX` if `pylatexenc` is installed on system
@@ -113,7 +113,7 @@ modified by the user.
113113
-- Characters that will replace the # at the start of headings
114114
headings = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
115115
-- Character to use for the bullet points in lists
116-
bullets = {"●","○","◆","◇"},
116+
bullets = { '●', '○', '◆', '◇' },
117117
-- Character that will replace the > at the start of block quotes
118118
quote = '┃',
119119
-- See :h 'conceallevel' for more information about meaning of values

lua/render-markdown/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function M.setup(opts)
7171
file_types = { 'markdown' },
7272
render_modes = { 'n', 'c' },
7373
headings = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
74-
bullets = {"","","",""},
74+
bullets = { '', '', '', '' },
7575
quote = '',
7676
conceal = {
7777
default = vim.opt.conceallevel:get(),

lua/render-markdown/ui.lua

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,6 @@ M.refresh = function()
3737
end)
3838
end
3939

40-
--- Walk through all parent nodes and count the number of nodes with type list
41-
--- to calculate the level of the given node
42-
---@param node TSNode
43-
---@return integer
44-
M.calculate_list_level = function(node)
45-
local candidate = node:parent()
46-
local level = 0
47-
while candidate ~= nil do
48-
local candidate_type = candidate:type()
49-
if candidate_type == "section" or candidate_type == "document" then
50-
-- when reaching a section or the document we are clearly at the
51-
-- top of the list
52-
break
53-
elseif candidate_type == "list" then
54-
-- found a list increase the level and continue
55-
level = level + 1
56-
end
57-
candidate = candidate:parent()
58-
end
59-
return level
60-
end
61-
6240
---@param root TSNode
6341
M.markdown = function(root)
6442
local highlights = state.config.highlights
@@ -95,10 +73,10 @@ M.markdown = function(root)
9573
-- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
9674
-- As a result we handle leading spaces here, can remove if this gets fixed upstream
9775
local _, leading_spaces = value:find('^%s*')
98-
-- Get the level of the list_marker by counting the number of parent list nodes
9976
local level = M.calculate_list_level(node)
100-
local bullet_marker = list.cycle(state.config.bullets, level)
101-
local virt_text = { string.rep(' ', leading_spaces or 0) .. bullet_marker, highlights.bullet }
77+
local bullet = list.cycle(state.config.bullets, level)
78+
79+
local virt_text = { string.rep(' ', leading_spaces or 0) .. bullet, highlights.bullet }
10280
vim.api.nvim_buf_set_extmark(0, M.namespace, start_row, start_col, {
10381
end_row = end_row,
10482
end_col = end_col,
@@ -167,6 +145,28 @@ M.markdown = function(root)
167145
end
168146
end
169147

148+
--- Walk through all parent nodes and count the number of nodes with type list
149+
--- to calculate the level of the given node
150+
---@param node TSNode
151+
---@return integer
152+
M.calculate_list_level = function(node)
153+
local level = 0
154+
local parent = node:parent()
155+
while parent ~= nil do
156+
local parent_type = parent:type()
157+
if vim.tbl_contains({ 'section', 'document' }, parent_type) then
158+
-- when reaching a section or the document we are clearly at the
159+
-- top of the list
160+
break
161+
elseif parent_type == 'list' then
162+
-- found a list increase the level and continue
163+
level = level + 1
164+
end
165+
parent = parent:parent()
166+
end
167+
return level
168+
end
169+
170170
---@param root TSNode
171171
M.markdown_inline = function(root)
172172
local highlights = state.config.highlights

0 commit comments

Comments
 (0)