From eead078f2df2fc0bf8436e9da7763f35c64bd81a Mon Sep 17 00:00:00 2001 From: dvs1 Date: Fri, 14 Mar 2025 20:06:34 +1000 Subject: Basic TOC. --- notYetAnotherWiki.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index 44f311c..f124eeb 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua @@ -31,6 +31,7 @@ local GlobalMetaData = { } local Files, Subs, xLinks = {}, {}, {} +local Context = {} -- Coz can't otherwise pass context through to the deeper Lunamark functions I'm overriding. local Template = '' local h = io.open("default.template", 'r') @@ -87,6 +88,7 @@ local toFile = function(name, key, value) local bits, bit = stringBits(name) local path = '' Files[name] = {} + Files[name].headers = {} Files[name].bits = bits Files[name].bit = bit for i, d in ipairs(bits) do @@ -107,6 +109,7 @@ local toFile = function(name, key, value) h = io.open(name .. '.md', 'r') if nil ~= h then -- print('Parsing ' .. name .. '.md') + Context = Files[name] body = h:read('*a') ; h:close() -- Deal with my typical double spaced sentence endings, and other things. local result = RE.compile( [=[{~ @@ -123,8 +126,9 @@ local toFile = function(name, key, value) {"[" {([^]])+} "]{style='color: " {([^}])+} "}" } -> "%2" / {"{#"[A-Za-z_]+"}"} -> '' / {"### [[edit](/bin/edit/Main/" {([^%nl])+} } -> '' / + {"#"+ " " {([^%nl])+} } -> header / . - )* ~}]=], { } ):match(body) + )* ~}]=], { header = function(a) table.insert(Context.headers, a); return a end } ):match(body) body = result -- {""} -> '' / -- {"[$]"} -> '$dlr$' / -- Replace $, coz otherwise it confuses things later. @@ -646,7 +650,6 @@ local LunamarkOpts = { } local Writer = Lunamark.writer.html5.new(LunamarkOpts) -- Can override the various writer functions, there's something for each of the basic HTML elements. -local Context = {} -- Coz can't otherwise pass context through to the deeper Lunamark functions I'm overriding. local lunaLinky = function(url) -- Fix up the links. if ('https://wiki.devuan.org/' ~= url) and ('https://fos.wiki.devuan.org/' ~= url) then -- TODO - This might be covering up a bug elsewhere. @@ -770,7 +773,18 @@ for name, file in pairs(Files) do url = Files[file.path .. '/' .. f].metadata.URL end if nil == title then title = f end - if bit == f then metadata.menu = metadata.menu .. '

' .. title .. '

' + if bit == f then + metadata.menu = metadata.menu .. '

' .. title .. '

' + for j, g in ipairs(file.headers) do + g = RE.gsub(g, '{[#]}', '  ') + g = RE.gsub(g, '{[ ]}', ' ') + local beg, en = RE.find(g, [['{']]) + if nil ~= beg then + g = string.sub(g, 1, beg - 7) + end +-- FIXME - if it's a linky, strip off the URL part. The Wiki audit has such things. + metadata.menu = metadata.menu .. '

' .. g .. '

' + end else if nil ~= url then metadata.menu = metadata.menu .. '

' .. title .. ' ☝

' else metadata.menu = metadata.menu .. '

' .. title .. '

' -- cgit v1.1