Skip to content

Commit 106946a

Browse files
Add support for block quotes > replacement
1 parent 882909d commit 106946a

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ Plugin to improve viewing Markdown files in Neovim
88

99
- Functions entirely inside of Neovim with no external windows
1010
- Changes between `rendered` view in normal mode and raw view in all other modes
11+
- Supports rendering `markdown` injected into other file types
1112
- Highlights headings with different groups depending on level and replaces `#`
1213
- Highlights code blocks to better stand out
1314
- Replaces whichever style bullet point is being used with provided character
15+
- Replaces block quote leading `>` with provided character
1416
- Updates table borders with better border characters, does NOT automatically align
1517
- Basic support for `LaTeX` if `pylatexenc` is installed on system
1618

@@ -64,6 +66,9 @@ require('render-markdown').setup({
6466
(list_marker_star)
6567
] @list_marker
6668
69+
(block_quote (block_quote_marker) @quote_marker)
70+
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
71+
6772
(pipe_table_header) @table_head
6873
(pipe_table_delimiter_row) @table_delim
6974
(pipe_table_row) @table_row
@@ -73,15 +78,18 @@ require('render-markdown').setup({
7378
-- vim modes that will show a rendered view of the markdown file, all other
7479
-- modes will be uneffected by this plugin
7580
render_modes = { 'n', 'c' },
76-
-- Characters that will replace the # at the start of markdown headings
81+
-- Characters that will replace the # at the start of headings
7782
headings = { '󰲡', '󰲣', '󰲥', '󰲧', '󰲩', '󰲫' },
7883
-- Character to use for the bullet point in lists
7984
bullet = '',
85+
-- Character that will replace the > at the start of block quotes
86+
quote = '',
87+
-- Define the highlight groups to use when rendering various components
8088
highlights = {
8189
heading = {
82-
-- Used for rendering heading line backgrounds
90+
-- Background of heading line
8391
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
84-
-- Used for rendering the foreground of the heading character only
92+
-- Foreground of heading character only
8593
foregrounds = {
8694
'markdownH1',
8795
'markdownH2',
@@ -91,18 +99,20 @@ require('render-markdown').setup({
9199
'markdownH6',
92100
},
93101
},
94-
-- Used when displaying code blocks
102+
-- Code blocks
95103
code = 'ColorColumn',
96-
-- Used when displaying bullet points in list
104+
-- Bullet points in list
97105
bullet = 'Normal',
98106
table = {
99-
-- Used when displaying header in a markdown table
107+
-- Header of a markdown table
100108
head = '@markup.heading',
101-
-- Used when displaying non header rows in a markdown table
109+
-- Non header rows in a markdown table
102110
row = 'Normal',
103111
},
104-
-- Used when displaying LaTeX
105-
latex = 'Special',
112+
-- LaTeX blocks
113+
latex = '@markup.math',
114+
-- Quote character in a block quote
115+
quote = '@markup.quote',
106116
},
107117
})
108118
```

demo/sample.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ if __name__ == "__main__":
3030
2. Item 2
3131
3. Item 3
3232

33+
> Quote line 1
34+
> Quote line 2
35+
3336
| Heading 1 | Heading 2 |
3437
| ------------ | ------------ |
3538
| Row 1 Item 1 | Row 1 Item 2 |

lua/render-markdown/init.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ local M = {}
1717
---@field public bullet? string
1818
---@field public table? UserTableHighlights
1919
---@field public latex? string
20+
---@field public quote? string
2021

2122
---@class UserConfig
2223
---@field public markdown_query? string
2324
---@field public file_types? string[]
2425
---@field public render_modes? string[]
2526
---@field public headings? string[]
2627
---@field public bullet? string
28+
---@field public quote? string
2729
---@field public highlights? UserHighlights
2830

2931
---@param opts UserConfig|nil
@@ -48,6 +50,9 @@ function M.setup(opts)
4850
(list_marker_star)
4951
] @list_marker
5052
53+
(block_quote (block_quote_marker) @quote_marker)
54+
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
55+
5156
(pipe_table_header) @table_head
5257
(pipe_table_delimiter_row) @table_delim
5358
(pipe_table_row) @table_row
@@ -56,6 +61,7 @@ function M.setup(opts)
5661
render_modes = { 'n', 'c' },
5762
headings = { '󰲡', '󰲣', '󰲥', '󰲧', '󰲩', '󰲫' },
5863
bullet = '',
64+
quote = '',
5965
highlights = {
6066
heading = {
6167
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },
@@ -74,7 +80,8 @@ function M.setup(opts)
7480
head = '@markup.heading',
7581
row = 'Normal',
7682
},
77-
latex = 'Special',
83+
latex = '@markup.math',
84+
quote = '@markup.quote',
7885
},
7986
}
8087
state.enabled = true

lua/render-markdown/state.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
---@field public bullet string
1313
---@field public table TableHighlights
1414
---@field public latex string
15+
---@field public quote string
1516

1617
---@class Config
1718
---@field public markdown_query string
1819
---@field public file_types string[]
1920
---@field public render_modes string[]
2021
---@field public headings string[]
2122
---@field public bullet string
23+
---@field public quote string
2224
---@field public highlights Highlights
2325

2426
---@class State

lua/render-markdown/ui.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ M.markdown = function(root)
7676
virt_text = { virt_text },
7777
virt_text_pos = 'overlay',
7878
})
79+
elseif capture == 'quote_marker' then
80+
local virt_text = { value:gsub('>', state.config.quote), highlights.quote }
81+
vim.api.nvim_buf_set_extmark(0, M.namespace, start_row, start_col, {
82+
end_row = end_row,
83+
end_col = end_col,
84+
virt_text = { virt_text },
85+
virt_text_pos = 'overlay',
86+
})
7987
elseif vim.tbl_contains({ 'table_head', 'table_delim', 'table_row' }, capture) then
8088
local row = value:gsub('|', '')
8189
if capture == 'table_delim' then

0 commit comments

Comments
 (0)