@@ -365,8 +365,32 @@ height: 0.7em; counter-increment: line-number; } ]]; + toc = [[ + + ]]; + tocFixed = [[ + @media (min-width: calc(@[width]:[100vw] + 20em)) { + ol.toc { + position: fixed; + padding-top: 1em; padding-bottom: 1em; + padding-right: 1em; + margin-top: 0; margin-bottom: 0; + right: 0; top: 0; bottom: 0; + max-width: calc(50vw - ((@[width]:[0]) / 2) - 3.5em); + overflow-y: auto; + } + @media (max-width: calc(@[width]:[100vw] + 30em)) { + ol.toc { + max-width: calc(100vw - ((@[width]:[0])) - 9.5em); + } + body { + margin-left: 5em; + } + } + } + ]]; } local stylesNeeded = {} @@ -470,9 +494,13 @@ local function getBlockRenderers(tag,elt,sr,catenate) local function insert_toc(b,s) - local lst = {tag = 'ol', attrs={}, nodes={}} + local lst = {tag = 'ol', attrs={class='toc'}, nodes={}} + stylesNeeded.toc = true + if opts['width'] then + stylesNeeded.tocFixed = true + end local stack = {lst} local top = function() return stack[#stack] end local all = s.origin.doc.secorder for i, sec in ipairs(all) do @@ -760,8 +788,9 @@ l = ss.math.lerp(tonumber(l), tbg, tfg) return tone(l, tonumber(sat), tonumber(sep), tonumber(alpha)) end end + css = css:gsub('@(%b[]):(%b[])', function(v,d) return opts[v:sub(2,-2)] or v:sub(2,-2) end) css = css:gsub('@(%w+)/([0-9.]+)(%b())', replace) css = css:gsub('@(%w+)(%b())', function(a,b) return replace(a,nil,b) end) css = css:gsub('@(%w+)/([0-9.]+)', replace) css = css:gsub('@(%w+)', function(a,b) return replace(a,nil,b) end)