Skip to content

Commit a196033

Browse files
committed
fix(doc)!: update default write_pre to remove top ===/--- delims
Details: - This complies better with `:h local-additions`. Resolve #2100
1 parent e96ef33 commit a196033

File tree

10 files changed

+18
-26
lines changed

10 files changed

+18
-26
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ There are following change types:
8787

8888
- Add support for working with files containing BOM bytes.
8989

90+
## mini.doc
91+
92+
### Refine
93+
94+
- Update default `write_pre` hook to remove `===` and `---` delimiters from the top to better comply with `:h local-additions`.
95+
9096
## mini.extra
9197

9298
### Expand

doc/mini-doc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Defaults ~
207207
doc = --<function: adds modeline>,
208208

209209
-- Applied before output file is written. Takes lines array as argument.
210-
write_pre = --<function: currently returns its input>,
210+
write_pre = --<function: remove delimiters at the top>,
211211

212212
-- Applied after output help file is written. Takes doc as argument.
213213
write_post = --<function: various convenience actions>,

lua/mini/doc.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,14 @@ MiniDoc.config = {
397397
--minidoc_replace_end
398398

399399
-- Applied before output file is written. Takes lines array as argument.
400-
--minidoc_replace_start write_pre = --<function: currently returns its input>,
401-
write_pre = function(l) return l end,
400+
--minidoc_replace_start write_pre = --<function: remove delimiters at the top>,
401+
write_pre = function(l)
402+
-- Remove first two lines with `======` and `------` delimiters to comply
403+
-- with `:h local-additions` template
404+
if l[1]:find('^=+$') ~= nil then table.remove(l, 1) end
405+
if l[1]:find('^-+$') ~= nil then table.remove(l, 1) end
406+
return l
407+
end,
402408
--minidoc_replace_end
403409

404410
-- Applied after output help file is written. Takes doc as argument.

readmes/mini-doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Here are code snippets for some common installation methods (use only one):
163163
doc = --<function: adds modeline>,
164164

165165
-- Applied before output file is written. Takes lines array as argument.
166-
write_pre = --<function: currently returns its input>,
166+
write_pre = --<function: remove delimiters at the top>,
167167

168168
-- Applied after output help file is written. Takes doc as argument.
169169
write_post = --<function: various convenience actions>,

scripts/minidoc.lua

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,8 @@ local modules = {
4848
'visits',
4949
}
5050

51-
local hooks = vim.deepcopy(MiniDoc.default_hooks)
52-
53-
hooks.write_pre = function(lines)
54-
-- Remove first two lines with `======` and `------` delimiters to comply
55-
-- with `:h local-additions` template
56-
table.remove(lines, 1)
57-
table.remove(lines, 1)
58-
return lines
59-
end
60-
61-
MiniDoc.generate({ 'lua/mini/init.lua' }, 'doc/mini-nvim.txt', { hooks = hooks })
51+
MiniDoc.generate({ 'lua/mini/init.lua' }, 'doc/mini-nvim.txt')
6252

6353
for _, m in ipairs(modules) do
64-
MiniDoc.generate({ 'lua/mini/' .. m .. '.lua' }, 'doc/mini-' .. m .. '.txt', { hooks = hooks })
54+
MiniDoc.generate({ 'lua/mini/' .. m .. '.lua' }, 'doc/mini-' .. m .. '.txt')
6555
end

tests/dir-doc/arguments/output_reference.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
==============================================================================
2-
------------------------------------------------------------------------------
31
This file should be used to generate output help file.
42
It also should respect `--` as annotation prefix (as test for respecting
53
`config` argument).

tests/dir-doc/custom-script/output_reference.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
==============================================================================
2-
------------------------------------------------------------------------------
31
File inside test for usage of custom script
42

53

tests/dir-doc/default-collation/default-collation_reference.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
==============================================================================
2-
------------------------------------------------------------------------------
31
File 'default-collation/init.lua'
42

53

tests/dir-doc/inference/inference_reference.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
==============================================================================
2-
------------------------------------------------------------------------------
31
Tests for inferring from afterline
42

53
------------------------------------------------------------------------------

tests/dir-doc/sections/sections_reference.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
==============================================================================
2-
------------------------------------------------------------------------------
31
*M.User*
42
`M.User`
53
Test for `@class`, `@field`, and `@type`

0 commit comments

Comments
 (0)