Skip to content

Commit 6f64bf6

Browse files
Bug Fix: handle quote blocks with empty lines
resolves: #41 # Details Quote blocks have continuations which differ depending on whether the previous line is empty and whether the current line is empty. Update the default query to handle the 2 scenarios when the previous line is empty and the current line is: - empty: `(block_quote (block_continuation) @quote_marker)` - not empty: `(block_quote (paragraph (block_continuation) @quote_marker))`
1 parent 99243b7 commit 6f64bf6

File tree

6 files changed

+53
-26
lines changed

6 files changed

+53
-26
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ require('render-markdown').setup({
109109
(task_list_marker_checked) @checkbox_checked
110110
111111
(block_quote (block_quote_marker) @quote_marker)
112+
(block_quote (block_continuation) @quote_marker)
113+
(block_quote (paragraph (block_continuation) @quote_marker))
112114
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
113115
114116
(pipe_table) @table

Diff for: demo/callout.gif

-6.18 KB
Loading

Diff for: demo/callout.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Note
22

33
> [!NOTE]
4+
>
45
> A regular note
6+
>
7+
> With a second paragraph
58
69
# Tip
710

Diff for: doc/render-markdown.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 June 19
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 June 24
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -146,6 +146,8 @@ modified by the user.
146146
(task_list_marker_checked) @checkbox_checked
147147

148148
(block_quote (block_quote_marker) @quote_marker)
149+
(block_quote (block_continuation) @quote_marker)
150+
(block_quote (paragraph (block_continuation) @quote_marker))
149151
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
150152

151153
(pipe_table) @table

Diff for: lua/render-markdown/init.lua

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ M.default_config = {
102102
(task_list_marker_checked) @checkbox_checked
103103
104104
(block_quote (block_quote_marker) @quote_marker)
105+
(block_quote (block_continuation) @quote_marker)
106+
(block_quote (paragraph (block_continuation) @quote_marker))
105107
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
106108
107109
(pipe_table) @table

Diff for: tests/callout_spec.lua

+43-25
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ async_tests.describe('callout.md', function()
77

88
local expected = {}
99

10-
-- Note
10+
local note_start = 0
1111
vim.list_extend(expected, {
1212
-- Heading
1313
{
14-
row = { 0, 1 },
14+
row = { note_start, note_start + 1 },
1515
col = { 0, 0 },
1616
hl_eol = true,
1717
hl_group = 'DiffAdd',
@@ -20,32 +20,50 @@ async_tests.describe('callout.md', function()
2020
},
2121
-- Quote start
2222
{
23-
row = { 2, 2 },
23+
row = { note_start + 2, note_start + 2 },
2424
col = { 0, 2 },
2525
virt_text = { { '', 'DiagnosticInfo' } },
2626
virt_text_pos = 'overlay',
2727
},
2828
-- Callout text
2929
{
30-
row = { 2, 2 },
30+
row = { note_start + 2, note_start + 2 },
3131
col = { 2, 9 },
3232
virt_text = { { '󰋽 Note', 'DiagnosticInfo' } },
3333
virt_text_pos = 'overlay',
3434
},
3535
-- Quote continued
3636
{
37-
row = { 3, 3 },
37+
row = { note_start + 3, note_start + 3 },
38+
col = { 0, 1 },
39+
virt_text = { { '', 'DiagnosticInfo' } },
40+
virt_text_pos = 'overlay',
41+
},
42+
{
43+
row = { note_start + 4, note_start + 4 },
44+
col = { 0, 2 },
45+
virt_text = { { '', 'DiagnosticInfo' } },
46+
virt_text_pos = 'overlay',
47+
},
48+
{
49+
row = { note_start + 5, note_start + 5 },
50+
col = { 0, 1 },
51+
virt_text = { { '', 'DiagnosticInfo' } },
52+
virt_text_pos = 'overlay',
53+
},
54+
{
55+
row = { note_start + 6, note_start + 6 },
3856
col = { 0, 2 },
3957
virt_text = { { '', 'DiagnosticInfo' } },
4058
virt_text_pos = 'overlay',
4159
},
4260
})
4361

44-
-- Tip
62+
local tip_start = 8
4563
vim.list_extend(expected, {
4664
-- Heading
4765
{
48-
row = { 5, 6 },
66+
row = { tip_start, tip_start + 1 },
4967
col = { 0, 0 },
5068
hl_eol = true,
5169
hl_group = 'DiffAdd',
@@ -54,32 +72,32 @@ async_tests.describe('callout.md', function()
5472
},
5573
-- Quote start
5674
{
57-
row = { 7, 7 },
75+
row = { tip_start + 2, tip_start + 2 },
5876
col = { 0, 2 },
5977
virt_text = { { '', 'DiagnosticOk' } },
6078
virt_text_pos = 'overlay',
6179
},
6280
-- Callout text
6381
{
64-
row = { 7, 7 },
82+
row = { tip_start + 2, tip_start + 2 },
6583
col = { 2, 8 },
6684
virt_text = { { '󰌶 Tip', 'DiagnosticOk' } },
6785
virt_text_pos = 'overlay',
6886
},
6987
-- Quote continued
7088
{
71-
row = { 8, 8 },
89+
row = { tip_start + 3, tip_start + 3 },
7290
col = { 0, 2 },
7391
virt_text = { { '', 'DiagnosticOk' } },
7492
virt_text_pos = 'overlay',
7593
},
7694
})
7795

78-
-- Important
96+
local important_start = 13
7997
vim.list_extend(expected, {
8098
-- Heading
8199
{
82-
row = { 10, 11 },
100+
row = { important_start, important_start + 1 },
83101
col = { 0, 0 },
84102
hl_eol = true,
85103
hl_group = 'DiffAdd',
@@ -88,32 +106,32 @@ async_tests.describe('callout.md', function()
88106
},
89107
-- Quote start
90108
{
91-
row = { 12, 12 },
109+
row = { important_start + 2, important_start + 2 },
92110
col = { 0, 2 },
93111
virt_text = { { '', 'DiagnosticHint' } },
94112
virt_text_pos = 'overlay',
95113
},
96114
-- Callout text
97115
{
98-
row = { 12, 12 },
116+
row = { important_start + 2, important_start + 2 },
99117
col = { 2, 14 },
100118
virt_text = { { '󰅾 Important', 'DiagnosticHint' } },
101119
virt_text_pos = 'overlay',
102120
},
103121
-- Quote continued
104122
{
105-
row = { 13, 13 },
123+
row = { important_start + 3, important_start + 3 },
106124
col = { 0, 2 },
107125
virt_text = { { '', 'DiagnosticHint' } },
108126
virt_text_pos = 'overlay',
109127
},
110128
})
111129

112-
-- Warning
130+
local warning_start = 18
113131
vim.list_extend(expected, {
114132
-- Heading
115133
{
116-
row = { 15, 16 },
134+
row = { warning_start, warning_start + 1 },
117135
col = { 0, 0 },
118136
hl_eol = true,
119137
hl_group = 'DiffAdd',
@@ -122,32 +140,32 @@ async_tests.describe('callout.md', function()
122140
},
123141
-- Quote start
124142
{
125-
row = { 17, 17 },
143+
row = { warning_start + 2, warning_start + 2 },
126144
col = { 0, 2 },
127145
virt_text = { { '', 'DiagnosticWarn' } },
128146
virt_text_pos = 'overlay',
129147
},
130148
-- Callout text
131149
{
132-
row = { 17, 17 },
150+
row = { warning_start + 2, warning_start + 2 },
133151
col = { 2, 12 },
134152
virt_text = { { '󰀪 Warning', 'DiagnosticWarn' } },
135153
virt_text_pos = 'overlay',
136154
},
137155
-- Quote continued
138156
{
139-
row = { 18, 18 },
157+
row = { warning_start + 3, warning_start + 3 },
140158
col = { 0, 2 },
141159
virt_text = { { '', 'DiagnosticWarn' } },
142160
virt_text_pos = 'overlay',
143161
},
144162
})
145163

146-
-- Caution
164+
local caution_start = 23
147165
vim.list_extend(expected, {
148166
-- Heading
149167
{
150-
row = { 20, 21 },
168+
row = { caution_start, caution_start + 1 },
151169
col = { 0, 0 },
152170
hl_eol = true,
153171
hl_group = 'DiffAdd',
@@ -156,21 +174,21 @@ async_tests.describe('callout.md', function()
156174
},
157175
-- Quote start
158176
{
159-
row = { 22, 22 },
177+
row = { caution_start + 2, caution_start + 2 },
160178
col = { 0, 2 },
161179
virt_text = { { '', 'DiagnosticError' } },
162180
virt_text_pos = 'overlay',
163181
},
164182
-- Callout text
165183
{
166-
row = { 22, 22 },
184+
row = { caution_start + 2, caution_start + 2 },
167185
col = { 2, 12 },
168186
virt_text = { { '󰳦 Caution', 'DiagnosticError' } },
169187
virt_text_pos = 'overlay',
170188
},
171189
-- Quote continued
172190
{
173-
row = { 23, 23 },
191+
row = { caution_start + 3, caution_start + 3 },
174192
col = { 0, 2 },
175193
virt_text = { { '', 'DiagnosticError' } },
176194
virt_text_pos = 'overlay',

0 commit comments

Comments
 (0)