aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authordvs12025-03-14 21:34:10 +1000
committerdvs12025-03-14 21:34:10 +1000
commit6be63601ba1c2cd76aa1eca2ee349492f3360aa4 (patch)
treeced739b8e0dad5e1daf0b9555835bc2b75660b34
parentBasic TOC. (diff)
downloadnotYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.zip
notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.gz
notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.bz2
notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.xz
Make the TOC actually work.
-rw-r--r--TODO.md2
-rwxr-xr-xnotYetAnotherWiki.lua16
2 files changed, 12 insertions, 6 deletions
diff --git a/TODO.md b/TODO.md
index 1c87341..acdcfe2 100644
--- a/TODO.md
+++ b/TODO.md
@@ -6,8 +6,8 @@ Make it perphekd!
6 6
7TOC 7TOC
8 8
9- Add anchors, so clicking on them goes to the heading.
10- Lengthy headings need to be tamed. 9- Lengthy headings need to be tamed.
10- Need a "go to top" linky after each heading now.
11 11
12Check the timestamps on the files, only update if source is newer than destination. Meh, it's already 600 times faster than the pandoc version. 12Check the timestamps on the files, only update if source is newer than destination. Meh, it's already 600 times faster than the pandoc version.
13 13
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
711end 711end
712 712
713function Writer.header(s, level)
714 local text = table.concat(s)
715 return '<h' .. level .. ' id="' .. RE.gsub(text, '{[ ]}', '_') .. '">' .. text .. '</h' .. level .. '>'
716end
713local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL. 717local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL.
714function Writer.link(lab, url, tit) 718function 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, '{[#]}', '&nbsp;&nbsp;') 783 local h = string.sub(RE.gsub(g, '{[#]}', ''), 2)
780 g = RE.gsub(g, '{[ ]}', '&nbsp;') 784 local l = string.len(g) - string.len(h)
781 local beg, en = RE.find(g, [['{']]) 785 g = h
786 h = RE.gsub(h, '{[ ]}', '&nbsp;')
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('&nbsp;', 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 .. ' &#9757;</a></p>' 795 if nil ~= url then metadata.menu = metadata.menu .. '<p><a href="' .. url .. '">' .. title .. ' &#9757;</a></p>'