Skip to content

Commit 1f9433d

Browse files
authored
feat: add code fence normalization for list blocks (#74)
1 parent f40d06e commit 1f9433d

4 files changed

Lines changed: 103 additions & 1 deletion

File tree

scripts/panvimdoc.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ local function indent(s, fl, ol)
5151
return table.concat(ret, "\n")
5252
end
5353

54+
-- Vim help code fences must start at column 1; list indentation can also
55+
-- swallow the blank line before the opening fence, so normalize both markers.
56+
local function normalize_list_codeblock_fences(s)
57+
s = s:gsub("\n +(>[^ \n]*)", "\n\n%1")
58+
s = s:gsub("\n +(<)", "\n%1")
59+
return s
60+
end
61+
5462
Writer = pandoc.scaffolding.Writer
5563

5664
local function inlines(ils)
@@ -323,7 +331,8 @@ end
323331
Writer.Block.BulletList = function(items)
324332
local buffer = {}
325333
items.content:map(function(item)
326-
table.insert(buffer, indent(blocks(item, "\n"), "- ", " "))
334+
local rendered = indent(blocks(item, "\n"), "- ", " ")
335+
table.insert(buffer, normalize_list_codeblock_fences(rendered))
327336
end)
328337
return table.concat(buffer, "\n") .. "\n\n"
329338
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# test code blocks
2+
3+
```lua
4+
print('code block at root')
5+
print('code block at root')
6+
print('code block at root')
7+
```
8+
9+
- list
10+
11+
```lua
12+
print('code block in list')
13+
print('code block in list')
14+
print('code block in list')
15+
```
16+
17+
- sublist
18+
- a
19+
20+
```lua
21+
print('a')
22+
print('a')
23+
print('a')
24+
```
25+
26+
- b
27+
28+
```lua
29+
print('b')
30+
print('b')
31+
print('b')
32+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
*test.txt* Test Description
2+
For NVIM v0.8.0 Last change: 2026 April 12
3+
4+
==============================================================================
5+
Table of Contents *test-table-of-contents*
6+
7+
1. test code blocks |test-test-code-blocks|
8+
9+
==============================================================================
10+
1. test code blocks *test-test-code-blocks*
11+
12+
>lua
13+
print('code block at root')
14+
print('code block at root')
15+
print('code block at root')
16+
<
17+
18+
- list
19+
20+
>lua
21+
print('code block in list')
22+
print('code block in list')
23+
print('code block in list')
24+
<
25+
- sublist
26+
- a
27+
28+
>lua
29+
print('a')
30+
print('a')
31+
print('a')
32+
<
33+
- b
34+
35+
>lua
36+
print('b')
37+
print('b')
38+
print('b')
39+
<
40+
41+
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
42+
43+
vim:tw=78:ts=8:noet:ft=help:norl:

tests/fixtures/render_cases.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
[
2+
{
3+
"name": "codeblocks_in_nested_lists_1",
4+
"input": "fixtures/render/codeblocks_in_nested_lists_1.md",
5+
"expected": "fixtures/render/codeblocks_in_nested_lists_1.txt",
6+
"options": {
7+
"toc": true,
8+
"dedup_subheadings": false,
9+
"treesitter": true,
10+
"demojify": false,
11+
"description": "Test Description",
12+
"vimversion": "NVIM v0.8.0",
13+
"ignore_rawblocks": true,
14+
"shift_heading_level_by": 0,
15+
"increment_heading_level_by": 0,
16+
"doc_mapping": true,
17+
"doc_mapping_project_name": true
18+
}
19+
},
220
{
321
"name": "dedupheadings_1",
422
"input": "fixtures/render/dedupheadings_1.md",

0 commit comments

Comments
 (0)