comparison website/src/lib/Shared.luan @ 1653:418b610e887b

docs work
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 31 Mar 2022 22:12:40 -0600
parents d5779a264a4a
children 2fbca5c84422
comparison
equal deleted inserted replaced
1652:d5779a264a4a 1653:418b610e887b
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local ipairs = Luan.ipairs or error() 3 local ipairs = Luan.ipairs or error()
4 local pairs = Luan.pairs or error()
4 5
5 6
6 local Shared = {} 7 local Shared = {}
7 8
8 function Shared.head() 9 function Shared.head()
28 29
29 function Shared.docs_header() 30 function Shared.docs_header()
30 header{[[<a href="/docs.html">Documentation</a>]]} 31 header{[[<a href="/docs.html">Documentation</a>]]}
31 end 32 end
32 33
34 local function show_toc(content)
35 %>
36 <ul>
37 <%
38 for id, info in pairs(content) do
39 %>
40 <li><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a>
41 <%
42 local subs = info.subs
43 if subs ~= nil then
44 show_toc(subs)
45 end
46 %>
47 </li>
48 <%
49 end
50 %>
51 </ul>
52 <%
53 end
54 Shared.show_toc = show_toc
55
56 local function nothing() end
57
58 local function show_content(content,h)
59 for id, info in pairs(content) do
60 %>
61 <div heading>
62 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>>
63 <a href="#c_<%=id%>">contents</a>
64 </div>
65 <%
66 (info.content or nothing)()
67 local subs = info.subs
68 if subs ~= nil then
69 show_content(subs,h+1)
70 end
71 end
72 end
73 Shared.show_content = show_content
74
33 return Shared 75 return Shared