From b594c4c30b672de27f55b5c1813cc36a99683389 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 7 Jan 2023 14:10:15 -0400 Subject: [PATCH] fix(commands/doc): strip html in headings --- nature/commands/doc.lua | 51 +++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/nature/commands/doc.lua b/nature/commands/doc.lua index bc45eea..3c831ee 100644 --- a/nature/commands/doc.lua +++ b/nature/commands/doc.lua @@ -10,6 +10,16 @@ commander.register('doc', function(args) ]] + local modules = table.map(fs.readdir(moddocPath), function(f) + return lunacolors.underline(lunacolors.blue(string.gsub(f, '.md', ''))) + end) + local doc = [[ +Welcome to Hilbish's documentation viewer! Here you can find +documentation for builtin functions and other things related +to Hilbish. + +Usage: doc
[subdoc] +Available sections: ]] .. table.concat(modules, ', ') if #args > 0 then local mod = args[1] @@ -63,35 +73,20 @@ commander.register('doc', function(args) if mod == 'api' then funcdocs = string.format(apidocHeader, vals.title, vals.description or 'no description.') .. funcdocs end - local backtickOccurence = 0 - local formattedFuncs = lunacolors.format(funcdocs:sub(1, #funcdocs - 1):gsub('`', function() - backtickOccurence = backtickOccurence + 1 - if backtickOccurence % 2 == 0 then - return '{reset}' - else - return '{underline}{green}' - end - end):gsub('#+.-\n', function(t) - return '{bold}{magenta}' .. t .. '{reset}' - end)) - print(formattedFuncs) + doc = funcdocs:sub(1, #funcdocs - 1) f:close() - - return end - local modules = table.map(fs.readdir(moddocPath), function(f) - return lunacolors.underline(lunacolors.blue(string.gsub(f, '.md', ''))) - end) - io.write [[ -Welcome to Hilbish's doc tool! Here you can find documentation for builtin -functions and other things. - -Usage: doc
[subdoc] -A section is a module or a literal section and a subdoc is a subsection for it. - -Available sections: ]] - io.flush() - - print(table.concat(modules, ', ')) + local backtickOccurence = 0 + print(lunacolors.format(doc:gsub('`', function() + backtickOccurence = backtickOccurence + 1 + if backtickOccurence % 2 == 0 then + return '{reset}' + else + return '{underline}{green}' + end + end):gsub('#+.-\n', function(t) + local signature = t:gsub('<.->(.-)', '{underline}%1'):gsub('\\', '<') + return '{bold}{yellow}' .. signature .. '{reset}' + end))) end)