Jump to content

Module:Auto compact TOC and Module:Auto compact TOC/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
a header could start at the beginning of the page (though it shouldn't in an article)
 
use css to merge with Template:Compact TOC
 
Line 3: Line 3:
local horizontal = require('Module:List').horizontal
local horizontal = require('Module:List').horizontal
local start = [[
local start = [[
__NOTOC__<div id="toc" class="toc plainlinks" role="navigation" aria-labelledby="mw-toc-heading">
__NOTOC__<div id="toc" class="compact-toc plainlinks" role="navigation" aria-labelledby="mw-toc-heading">
<div class="toctitle"><h2 id="mw-toc-heading">Contents</h2></div>
<div class="compact-toctitle"><span id="compact-tocheading">Contents</span></div>
]]
]]


Line 28: Line 28:
local letters = Array()
local letters = Array()
-- Find uppermost headers containing a single ASCII letter.
-- Find uppermost headers containing a single ASCII letter.
for letter in content:gmatch "%f[^\n%z]==%s*(%a)%s*==%f[^=]" do
for letter in content:gmatch "%f[^\n]==%s*(%a)%s*==%f[^=]" do
letter = letter:upper()
letter = letter:upper()
letters:insert(make_TOC_item(letter))
letters:insert(make_TOC_item(letter))
Line 38: Line 38:
"See also", "References", "Notes", "Further reading", "External links",
"See also", "References", "Notes", "Further reading", "External links",
}
}
for header in content:gmatch "%f[^\n%z]==%s*(..-)%s*==%f[^=]" do
for header in content:gmatch "%f[^\n]==%s*(..-)%s*==%f[^=]" do
if other_headers[header] then
if other_headers[header] then
rest:insert(make_TOC_item(header))
rest:insert(make_TOC_item(header))