Skip to content

Commit d99596d

Browse files
committed
Improve documentation generation.
1 parent 4f476d0 commit d99596d

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

_scripts/mini_nvim.lua

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,22 @@ local add_empty_lines = function(lines)
101101
end
102102

103103
local add_help_syntax = function(lines, tags)
104-
local code_ranges = {}
104+
local bad_ranges = {}
105105

106-
local replace_not_in_code_ranges = function(s, pat, repl)
106+
local replace_not_in_ranges = function(s, pat, repl)
107107
local res = s:gsub(pat, function(col, text)
108-
for _, range in ipairs(code_ranges) do
108+
for _, range in ipairs(bad_ranges) do
109109
if range[1] <= col and col < range[2] then return end
110110
end
111111
return type(repl) == 'string' and string.format(repl, text) or repl(text)
112112
end)
113113
return res
114114
end
115115

116-
local populate_code_ranges = function(s)
117-
code_ranges = {}
118-
s:gsub('`().-()`', function(from, to) table.insert(code_ranges, { from, to }) end)
116+
local populate_bad_ranges = function(s)
117+
bad_ranges = {}
118+
s:gsub('`().-()`', function(from, to) table.insert(bad_ranges, { from, to }) end)
119+
s:gsub('()%b[]%b()()', function(from, to) table.insert(bad_ranges, { from, to }) end)
119120
end
120121

121122
local repl_link = function(m)
@@ -131,11 +132,14 @@ local add_help_syntax = function(lines, tags)
131132
local repl_right_anchor = function(m)
132133
-- Transform right anchor into a heading (for table of contents entry).
133134
-- Compute more natural title. Common tag->title transformations:
134-
-- - `*MiniAi*` -> "Overview"
135+
-- - `*MiniAi*` -> "Module" ("Overview" is commonly used later as
136+
-- a 'MiniXxx-overview' tag).
135137
-- - `*MiniAi.find_textobject()*` -> "find_textobject()"
136138
-- - `*MiniAi-builtin-textobjects*` -> "Builtin textobjects"
139+
-- - `*mini.nvim-disabling-recipes*` -> "Disabling recipes"
137140
-- - `:DepsAdd` -> ":DepsAdd"
138-
local text = m:find('^Mini%w+$') ~= nil and 'Overview' or (m:match('^Mini%w+(%W.+)$') or m)
141+
local text = m:find('^Mini%w+$') ~= nil and 'Module'
142+
or (m:match('^Mini%w+(%W.+)$') or m:match('^mini%.%w+(%W.+)$') or m)
139143
local char_one, char_two = text:sub(1, 1), text:sub(2, 2)
140144
local title = char_one == '.' and text:sub(2)
141145
or (char_one == '-' and (char_two:upper() .. text:sub(3):gsub('%-', ' ')) or text)
@@ -160,24 +164,24 @@ local add_help_syntax = function(lines, tags)
160164

161165
for i, _ in iter_noncode(lines) do
162166
-- Collect `xxx` ranges within line to not act inside of them
163-
populate_code_ranges(lines[i])
167+
populate_bad_ranges(lines[i])
164168

165169
-- `|xxx|` is used to add a a link to a tag anchor
166-
lines[i] = replace_not_in_code_ranges(lines[i], '()|([%w%.-_<>%(%)]-)|', repl_link)
170+
lines[i] = replace_not_in_ranges(lines[i], '()|(%S-)|', repl_link)
167171
-- - Recompute code ranges because adding links adds one
168-
populate_code_ranges(lines[i])
172+
populate_bad_ranges(lines[i])
169173

170174
-- `<xxx>` is used to show keys and (often) table fields. Escape to not be
171175
-- treated as HTML tags. Do so before adding any custom HTML tags.
172-
lines[i] = replace_not_in_code_ranges(lines[i], '()<(%S-)>', '<span class="help-syntax-keys">\\<%s\\></span>')
176+
lines[i] = replace_not_in_ranges(lines[i], '()<(%S-)>', '<span class="help-syntax-keys">\\<%s\\></span>')
173177

174178
-- `{xxx}` is used to add special highlighting. Usually arguments.
175-
lines[i] = replace_not_in_code_ranges(lines[i], '(){(%S-)}', '<span class="help-syntax-special">{%s}</span>')
179+
lines[i] = replace_not_in_ranges(lines[i], '(){(%S-)}', '<span class="help-syntax-special">{%s}</span>')
176180

177181
-- `*xxx*` is used to add an anchor to a tag. Treat right aligned anchors
178182
-- as start of the section (adds to table of contents).
179183
lines[i] = lines[i]:gsub('^ +%*(.-)%*$', repl_right_anchor)
180-
lines[i] = replace_not_in_code_ranges(lines[i], '()%*(%S-)%*', repl_anchor)
184+
lines[i] = replace_not_in_ranges(lines[i], '()%*(%S-)%*', repl_anchor)
181185

182186
-- `Xxx ~` is used to add subsections within section denoted by ruler
183187
lines[i] = lines[i]:gsub('^(.+) ~$', repl_section_header)
@@ -225,6 +229,11 @@ local add_hierarchical_heading_anchors = function(lines)
225229
end
226230
end
227231

232+
local add_source_note = function(lines)
233+
table.insert(lines, 1, "_Generated from the `main` branch of 'mini.nvim'_")
234+
table.insert(lines, 2, '')
235+
end
236+
228237
local adjust_header_footer = function(lines, title)
229238
-- Add informative header for better search
230239
table.insert(lines, 1, '---')
@@ -255,6 +264,7 @@ local create_help = function()
255264
add_help_syntax(lines, help_tags)
256265
adjust_alignment(lines)
257266
add_hierarchical_heading_anchors(lines)
267+
add_source_note(lines)
258268
adjust_header_footer(lines, basename:gsub('%-', '.') .. ' documentation')
259269

260270
local out_path = string.format('%s/%s.qmd', help_path, basename)
@@ -307,6 +317,7 @@ local adjust_readmes = function()
307317

308318
replace_demo_link(lines)
309319
replace_help_links(lines)
320+
add_source_note(lines)
310321
adjust_header_footer(lines, 'mini.' .. file:match('(%w+)%.md$'))
311322
add_doc_links(lines)
312323

@@ -330,6 +341,7 @@ local adjust_changelog = function()
330341
local path = 'mini.nvim/CHANGELOG.md'
331342
local lines = vim.fn.readfile(path)
332343

344+
add_source_note(lines)
333345
add_hierarchical_heading_anchors(lines)
334346

335347
vim.fn.writefile(lines, path)

theme/brand-dark.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ defaults:
6262
navbar-fg: "#E6E2DB"
6363
code-block-bg: "#11262D"
6464
rules: |
65+
p {
66+
margin-top: 0em;
67+
margin-bottom: 0.5em;
68+
}
69+
h2, h3, h4 {
70+
margin-top: 1em;
71+
margin-bottom: 0.25em;
72+
}
6573
p pre code:not(.sourceCode),
6674
li pre code:not(.sourceCode),
6775
pre code:not(.sourceCode) {

theme/brand-light.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ defaults:
6363
navbar-fg: "#1D1E23"
6464
code-block-bg: "#E9E1DD"
6565
rules: |
66+
p {
67+
margin-top: 0em;
68+
margin-bottom: 0.5em;
69+
}
70+
h2, h3, h4 {
71+
margin-top: 1em;
72+
margin-bottom: 0.25em;
73+
}
6674
p pre code:not(.sourceCode),
6775
li pre code:not(.sourceCode),
6876
pre code:not(.sourceCode) {

0 commit comments

Comments
 (0)