Skip to content

Commit

Permalink
fix(docgen): fix incorrect markdown indentation in wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed May 31, 2023
1 parent 1afcaf8 commit 2bf6e63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
19 changes: 8 additions & 11 deletions docgen/docgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@ end

--- Converts a ConfigOptionData struct to a html node in the resulting HTML document
---@param configuration_option ConfigOptionArray #The config option to render
---@param indent number? #How far to indent the text by. Should not be set manually.
---@param open boolean? #Whether to auto-open the generated `<details>` tag. Defaults to false.
---@return string[] #A list of markdown tables corresponding to the rendered element.
docgen.render = function(configuration_option, indent)
indent = indent or 0
docgen.render = function(configuration_option, open)
open = open or false

local self = configuration_option.self

Expand All @@ -594,7 +594,7 @@ docgen.render = function(configuration_option, indent)
end)()

local basis = {
"* <details" .. (indent == 0 and " open>" or ">"),
"* <details" .. (open and " open>" or ">"),
"",
((self.data.name or ""):match("^%s*$") and "<summary>" or table.concat({
"<summary><code>",
Expand Down Expand Up @@ -627,26 +627,23 @@ docgen.render = function(configuration_option, indent)
})
end

vim.list_extend(basis, docgen.htmlify(configuration_option, indent))
vim.list_extend(basis, docgen.htmlify(configuration_option))
vim.list_extend(basis, {
"",
"</details>",
})

for i, str in ipairs(basis) do
basis[i] = string.rep(" ", indent + (i > 1 and 2 or 0)) .. str
basis[i] = string.rep(" ", 2 - (i == 1 and 2 or 0)) .. str
end

return basis
end

--- Converts an object directly into HTML, with no extra fluff.
---@param configuration_option ConfigOptionArray
---@param indent number? #How far to indent the text by. Should not be set manually
---@return string[] #An array of markdown strings with the rendered HTML inside
docgen.htmlify = function(configuration_option, indent)
indent = indent or 0

docgen.htmlify = function(configuration_option)
local self = configuration_option.self

local result = {}
Expand All @@ -672,7 +669,7 @@ docgen.htmlify = function(configuration_option, indent)
local subitem = configuration_option[name_or_index]

if subitem then
vim.list_extend(result, docgen.render(subitem, indent + 1))
vim.list_extend(result, docgen.render(subitem))
end
end

Expand Down
10 changes: 9 additions & 1 deletion docgen/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
local docgen = require("docgen")
local fileio = require("fileio")

--- CONFIGURABLE DOCGEN BEHAVIOUR
--- Tweak as you see fit.
local config = {
--- When true, will auto-unfold the top-level <details>
--- tags generated when rendering module configuration options.
auto_open_first_level_tags = true,
}

---@type Modules
local modules = {
--[[
Expand All @@ -25,7 +33,7 @@ local function concat_configuration_options(configuration_options)
end)
for _, values in pairs(unrolled) do
vim.list_extend(result, docgen.render(values[2]))
vim.list_extend(result, docgen.render(values[2], config.auto_open_first_level_tags))
table.insert(result, "")
end
Expand Down

0 comments on commit 2bf6e63

Please sign in to comment.