Skip to content

Commit 7acc1bf

Browse files
Add sign text for headings & code blocks
1 parent be3f6e3 commit 7acc1bf

20 files changed

+204
-19
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Plugin to improve viewing Markdown files in Neovim
2727
- Block quotes: replace leading `>` with provided icon
2828
- Tables: replace border characters, does NOT automatically align
2929
- [Callouts](https://github.com/orgs/community/discussions/16925)
30-
- Base set as well as custom ones
30+
- Github & Obsidian out of the box, supports user defined as well
3131
- Custom checkbox states, function similar to `callouts`
3232
- `LaTeX` blocks: renders formulas if `latex` parser and `pylatexenc` are installed
3333
- Disable rendering when file is larger than provided value
@@ -172,18 +172,21 @@ require('render-markdown').setup({
172172
-- The 'level' is used to index into the array using a cycle
173173
-- The result is left padded with spaces to hide any additional '#'
174174
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
175+
-- Added to the sign column
176+
-- The 'level' is used to index into the array using a cycle
177+
signs = { '󰫎 ' },
175178
-- The 'level' is used to index into the array using a clamp
176179
-- Highlight for the heading icon and extends through the entire line
177180
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
178181
-- The 'level' is used to index into the array using a clamp
179-
-- Highlight for the heading icon only
182+
-- Highlight for the heading and sign icons
180183
foregrounds = { 'markdownH1', 'markdownH2', 'markdownH3', 'markdownH4', 'markdownH5', 'markdownH6' },
181184
},
182185
code = {
183186
-- Determines how code blocks & inline code are rendered:
184187
-- none: disables all rendering
185188
-- normal: adds highlight group to code blocks & inline code
186-
-- language: adds language icon & name above code blocks
189+
-- language: adds language icon to sign column and icon + name above code blocks
187190
-- full: normal + language
188191
style = 'full',
189192
-- Highlight for code blocks & inline code
@@ -326,11 +329,14 @@ require('render-markdown').setup({
326329
-- The 'level' is used to index into the array using a cycle
327330
-- The result is left padded with spaces to hide any additional '#'
328331
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
332+
-- Added to the sign column
333+
-- The 'level' is used to index into the array using a cycle
334+
signs = { '󰫎 ' },
329335
-- The 'level' is used to index into the array using a clamp
330336
-- Highlight for the heading icon and extends through the entire line
331337
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
332338
-- The 'level' is used to index into the array using a clamp
333-
-- Highlight for the heading icon only
339+
-- Highlight for the heading and sign icons
334340
foregrounds = { 'markdownH1', 'markdownH2', 'markdownH3', 'markdownH4', 'markdownH5', 'markdownH6' },
335341
},
336342
})
@@ -344,7 +350,7 @@ require('render-markdown').setup({
344350
-- Determines how code blocks & inline code are rendered:
345351
-- none: disables all rendering
346352
-- normal: adds highlight group to code blocks & inline code
347-
-- language: adds language icon & name above code blocks
353+
-- language: adds language icon to sign column and icon + name above code blocks
348354
-- full: normal + language
349355
style = 'full',
350356
-- Highlight for code blocks & inline code

demo/box_dash_quote.gif

592 Bytes
Loading

demo/callout.gif

64.4 KB
Loading

demo/heading_code.gif

36.9 KB
Loading

demo/latex.gif

3.77 KB
Loading

demo/list_table.gif

66.1 KB
Loading

doc/render-markdown.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Plugin to improve viewing Markdown files in Neovim
5454
- Block quotes: replace leading `>` with provided icon
5555
- Tables: replace border characters, does NOT automatically align
5656
- Callouts <https://github.com/orgs/community/discussions/16925>
57-
- Base set as well as custom ones
57+
- Github & Obsidian out of the box, supports user defined as well
5858
- Custom checkbox states, function similar to `callouts`
5959
- `LaTeX` blocks: renders formulas if `latex` parser and `pylatexenc` are installed
6060
- Disable rendering when file is larger than provided value
@@ -208,18 +208,21 @@ Full Default Configuration ~
208208
-- The 'level' is used to index into the array using a cycle
209209
-- The result is left padded with spaces to hide any additional '#'
210210
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
211+
-- Added to the sign column
212+
-- The 'level' is used to index into the array using a cycle
213+
signs = { '󰫎 ' },
211214
-- The 'level' is used to index into the array using a clamp
212215
-- Highlight for the heading icon and extends through the entire line
213216
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
214217
-- The 'level' is used to index into the array using a clamp
215-
-- Highlight for the heading icon only
218+
-- Highlight for the heading and sign icons
216219
foregrounds = { 'markdownH1', 'markdownH2', 'markdownH3', 'markdownH4', 'markdownH5', 'markdownH6' },
217220
},
218221
code = {
219222
-- Determines how code blocks & inline code are rendered:
220223
-- none: disables all rendering
221224
-- normal: adds highlight group to code blocks & inline code
222-
-- language: adds language icon & name above code blocks
225+
-- language: adds language icon to sign column and icon + name above code blocks
223226
-- full: normal + language
224227
style = 'full',
225228
-- Highlight for code blocks & inline code
@@ -361,11 +364,14 @@ HEADINGS *render-markdown-setup-headings*
361364
-- The 'level' is used to index into the array using a cycle
362365
-- The result is left padded with spaces to hide any additional '#'
363366
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
367+
-- Added to the sign column
368+
-- The 'level' is used to index into the array using a cycle
369+
signs = { '󰫎 ' },
364370
-- The 'level' is used to index into the array using a clamp
365371
-- Highlight for the heading icon and extends through the entire line
366372
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
367373
-- The 'level' is used to index into the array using a clamp
368-
-- Highlight for the heading icon only
374+
-- Highlight for the heading and sign icons
369375
foregrounds = { 'markdownH1', 'markdownH2', 'markdownH3', 'markdownH4', 'markdownH5', 'markdownH6' },
370376
},
371377
})
@@ -380,7 +386,7 @@ CODE BLOCKS *render-markdown-setup-code-blocks*
380386
-- Determines how code blocks & inline code are rendered:
381387
-- none: disables all rendering
382388
-- normal: adds highlight group to code blocks & inline code
383-
-- language: adds language icon & name above code blocks
389+
-- language: adds language icon to sign column and icon + name above code blocks
384390
-- full: normal + language
385391
style = 'full',
386392
-- Highlight for code blocks & inline code

lua/render-markdown/handler/markdown.lua

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ M.render_node = function(namespace, buf, capture, node)
4848
virt_text_pos = 'overlay',
4949
hl_eol = true,
5050
})
51+
52+
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, start_col, {
53+
end_row = end_row,
54+
end_col = end_col,
55+
sign_text = list.cycle(heading.signs, level),
56+
sign_hl_group = foreground,
57+
})
5158
elseif capture == 'dash' then
5259
local dash = state.config.dash
5360
local width = vim.api.nvim_win_get_width(util.buf_to_win(buf))
@@ -72,14 +79,20 @@ M.render_node = function(namespace, buf, capture, node)
7279
if not vim.tbl_contains({ 'language', 'full' }, code.style) then
7380
return
7481
end
75-
-- Requires inline extmarks
76-
if not util.has_10 then
77-
return
78-
end
7982
local icon, icon_highlight = icons.get(value)
8083
if icon == nil or icon_highlight == nil then
8184
return
8285
end
86+
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, start_col, {
87+
end_row = end_row,
88+
end_col = end_col,
89+
sign_text = icon,
90+
sign_hl_group = icon_highlight,
91+
})
92+
-- Requires inline extmarks
93+
if not util.has_10 then
94+
return
95+
end
8396
local highlight = { icon_highlight }
8497
if code.style == 'full' then
8598
highlight = { icon_highlight, code.highlight }

lua/render-markdown/health.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ function M.check_config(config)
144144
local heading = config.heading
145145
append_errors('heading', {
146146
icons = { heading.icons, 'table' },
147+
signs = { heading.signs, 'table' },
147148
backgrounds = { heading.backgrounds, 'table' },
148149
foregrounds = { heading.foregrounds, 'table' },
149150
})
150151
all_strings('heading.icons', heading.icons)
152+
all_strings('heading.signs', heading.signs)
151153
all_strings('heading.backgrounds', heading.backgrounds)
152154
all_strings('heading.foregrounds', heading.foregrounds)
153155

lua/render-markdown/init.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ local M = {}
4242

4343
---@class render.md.UserHeading
4444
---@field public icons? string[]
45+
---@field public signs? string[]
4546
---@field public backgrounds? string[]
4647
---@field public foregrounds? string[]
4748

@@ -145,18 +146,21 @@ M.default_config = {
145146
-- The 'level' is used to index into the array using a cycle
146147
-- The result is left padded with spaces to hide any additional '#'
147148
icons = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
149+
-- Added to the sign column
150+
-- The 'level' is used to index into the array using a cycle
151+
signs = { '󰫎 ' },
148152
-- The 'level' is used to index into the array using a clamp
149153
-- Highlight for the heading icon and extends through the entire line
150154
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
151155
-- The 'level' is used to index into the array using a clamp
152-
-- Highlight for the heading icon only
156+
-- Highlight for the heading and sign icons
153157
foregrounds = { 'markdownH1', 'markdownH2', 'markdownH3', 'markdownH4', 'markdownH5', 'markdownH6' },
154158
},
155159
code = {
156160
-- Determines how code blocks & inline code are rendered:
157161
-- none: disables all rendering
158162
-- normal: adds highlight group to code blocks & inline code
159-
-- language: adds language icon & name above code blocks
163+
-- language: adds language icon to sign column and icon + name above code blocks
160164
-- full: normal + language
161165
style = 'full',
162166
-- Highlight for code blocks & inline code

0 commit comments

Comments
 (0)