diff options
author | dvs1 | 2025-03-14 21:34:10 +1000 |
---|---|---|
committer | dvs1 | 2025-03-14 21:34:10 +1000 |
commit | 6be63601ba1c2cd76aa1eca2ee349492f3360aa4 (patch) | |
tree | ced739b8e0dad5e1daf0b9555835bc2b75660b34 /notYetAnotherWiki.lua | |
parent | Basic TOC. (diff) | |
download | notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.zip notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.gz notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.bz2 notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.xz |
Make the TOC actually work.
Diffstat (limited to 'notYetAnotherWiki.lua')
-rwxr-xr-x | notYetAnotherWiki.lua | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index f124eeb..3590af7 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua | |||
@@ -710,6 +710,10 @@ local lunaLinky = function(url) -- Fix up the links. | |||
710 | return url | 710 | return url |
711 | end | 711 | end |
712 | 712 | ||
713 | function Writer.header(s, level) | ||
714 | local text = table.concat(s) | ||
715 | return '<h' .. level .. ' id="' .. RE.gsub(text, '{[ ]}', '_') .. '">' .. text .. '</h' .. level .. '>' | ||
716 | end | ||
713 | local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL. | 717 | local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL. |
714 | function Writer.link(lab, url, tit) | 718 | function Writer.link(lab, url, tit) |
715 | return OgWriterLink(lab, lunaLinky(url), tit) | 719 | return OgWriterLink(lab, lunaLinky(url), tit) |
@@ -776,14 +780,16 @@ for name, file in pairs(Files) do | |||
776 | if bit == f then | 780 | if bit == f then |
777 | metadata.menu = metadata.menu .. '<p>' .. title .. '</p>' | 781 | metadata.menu = metadata.menu .. '<p>' .. title .. '</p>' |
778 | for j, g in ipairs(file.headers) do | 782 | for j, g in ipairs(file.headers) do |
779 | g = RE.gsub(g, '{[#]}', ' ') | 783 | local h = string.sub(RE.gsub(g, '{[#]}', ''), 2) |
780 | g = RE.gsub(g, '{[ ]}', ' ') | 784 | local l = string.len(g) - string.len(h) |
781 | local beg, en = RE.find(g, [['{']]) | 785 | g = h |
786 | h = RE.gsub(h, '{[ ]}', ' ') | ||
787 | local beg, en = RE.find(h, [['{']]) | ||
782 | if nil ~= beg then | 788 | if nil ~= beg then |
783 | g = string.sub(g, 1, beg - 7) | 789 | g = string.sub(h, 1, beg - 7) |
784 | end | 790 | end |
785 | -- FIXME - if it's a linky, strip off the URL part. The Wiki audit has such things. | 791 | -- FIXME - if it's a linky, strip off the URL part. The Wiki audit has such things. |
786 | metadata.menu = metadata.menu .. '<p style="font-size: 0.80em;">' .. g .. '</p>' | 792 | metadata.menu = metadata.menu .. '<p>' .. string.rep(' ', l) .. '<a style="font-size: 0.80em;" href="#' .. RE.gsub(g, '{[ ]}', '_') .. '">' .. h .. '</a></p>' |
787 | end | 793 | end |
788 | else | 794 | else |
789 | if nil ~= url then metadata.menu = metadata.menu .. '<p><a href="' .. url .. '">' .. title .. ' ☝</a></p>' | 795 | if nil ~= url then metadata.menu = metadata.menu .. '<p><a href="' .. url .. '">' .. title .. ' ☝</a></p>' |