diff --git a/nature/commands/doc.lua b/nature/commands/doc.lua index d82832a..dc3fe9c 100644 --- a/nature/commands/doc.lua +++ b/nature/commands/doc.lua @@ -20,15 +20,22 @@ local function transformHTMLandMD(text) return string.format('%s - %s', entry1, entry2) end) :gsub('^\n\n', '\n') - :gsub('
', '{separator}') - :gsub('<.->', '') :gsub('\n%s+\n', '\n\n') - :gsub('#+ (.-\n)', function(heading) return lunacolors.blue(lunacolors.bold('→ ' .. heading)) end) + :gsub(' \n', '\n\n') + :gsub('{{< (%w+) `(.-)` >}}', function(shortcode, text) + return docfuncs.renderInfoBlock(shortcode, text) + end) :gsub('```(%w+)\n(.-)```', function(lang, text) return docfuncs.renderCodeBlock(text) end) - :gsub('`(.-)`', lunacolors.cyan) + :gsub('```\n(.-)\n```', function(text) + return docfuncs.renderCodeBlock(text) + end) + :gsub('`[^\n].-`', lunacolors.cyan) + :gsub('#+ (.-\n)', function(heading) return lunacolors.blue(lunacolors.bold('→ ' .. heading)) end) :gsub('%*%*(.-)%*%*', lunacolors.bold) + :gsub('
', '{separator}') + :gsub('<.->', '') end commander.register('doc', function(args, sinks) @@ -54,10 +61,9 @@ Available sections: ]] .. table.concat(modules, ', ') local vals = {} local docs = d - local valsStr = docs:match '%-%-%-\n([^%-%-%-]+)\n' - print(valsStr) + local valsStr = docs:match '^%-%-%-\n.-\n%-%-%-' if valsStr then - docs = docs:sub(valsStr:len() + 10, #docs) + docs = docs:sub(valsStr:len() + 2, #docs) -- parse vals local lines = string.split(valsStr, '\n') @@ -154,7 +160,7 @@ Available sections: ]] .. table.concat(modules, ', ') end - local doc, vals = handleYamlInfo(#args == 0 and doc or formatDocText(f:read '*a':gsub('-([%d]+)', '%1'))) + local doc, vals = handleYamlInfo(#args == 0 and doc or formatDocText(f:read '*a')) if #moddocs ~= 0 and f then doc = doc .. '\nSubdocs: ' .. table.concat(subdocs, ', ') .. '\n\n' end @@ -172,8 +178,8 @@ Available sections: ]] .. table.concat(modules, ', ') end local f = io.open(moddocPath .. sdFile, 'rb') - local doc, vals = handleYamlInfo(f:read '*a':gsub('-([%d]+)', '%1')) - local page = Page(vals.title, formatDocText(doc)) + local doc, vals = handleYamlInfo(formatDocText(f:read '*a')) + local page = Page(vals.title or sdName, doc) page.description = vals.description gh:addPage(page) end diff --git a/nature/doc.lua b/nature/doc.lua index 872f18f..657af51 100644 --- a/nature/doc.lua +++ b/nature/doc.lua @@ -24,4 +24,24 @@ function M.renderCodeBlock(text) return '\n' .. lunacolors.format('{greyBg}' .. table.concat(lines, '\n')) .. '\n' end +function M.renderInfoBlock(type, text) + local longest = 0 + local lines = string.split(text:gsub('\t', ' '), '\n') + + for i, line in ipairs(lines) do + local len = line:len() + if len > longest then longest = len end + end + + for i, line in ipairs(lines) do + lines[i] = ' ' .. M.highlight(line:sub(0, longest)) + .. string.rep(' ', longest - line:len()) .. ' ' + end + + local heading + if type == 'warning' then + heading = lunacolors.yellowBg(lunacolors.black(' ⚠ Warning ')) + end + return '\n' .. heading .. '\n' .. lunacolors.format('{greyBg}' .. table.concat(lines, '\n')) .. '\n' +end return M