Module:Auto compact TOC: Difference between revisions
Appearance
Content deleted Content added
heh |
m remove whitespace above ToC |
||
Line 2: | Line 2: | ||
local start = [[ |
local start = [[ |
||
__NOTOC__ |
__NOTOC__<!-- |
||
<div role="navigation" id="toc" class="toc plainlinks hlist" aria-labelledby="tocheading" style="text-align:left;"> |
--><div role="navigation" id="toc" class="toc plainlinks hlist" aria-labelledby="tocheading" style="text-align:left;"> |
||
<div id="toctitle" class="toctitle" style="text-align:center;"><span id="tocheading" style="font-weight:bold;">Contents</span></div> |
<div id="toctitle" class="toctitle" style="text-align:center;"><span id="tocheading" style="font-weight:bold;">Contents</span></div> |
||
<div style="margin:auto;white-space:nowrap;"> |
<div style="margin:auto;white-space:nowrap;"> |
Revision as of 03:02, 21 February 2019
![]() | This module depends on the following other modules: |
Implements {{auto compact TOC}}
local p = {}
local start = [[
__NOTOC__<!--
--><div role="navigation" id="toc" class="toc plainlinks hlist" aria-labelledby="tocheading" style="text-align:left;">
<div id="toctitle" class="toctitle" style="text-align:center;"><span id="tocheading" style="font-weight:bold;">Contents</span></div>
<div style="margin:auto;white-space:nowrap;">
]]
local close = [[</div></div>]]
function p.make_TOC()
local content = mw.title.getCurrentTitle():getContent()
local letters = setmetatable({}, { __index = table })
-- Find uppermost headers containing a single ASCII letter.
for letter in content:gmatch "%f[^\n]==%s*(%a)%s*==%f[^=]" do
letter = letter:upper()
letters:insert(("* [[#%s|%s]]"):format(letter, letter))
end
return start .. letters:concat("\n") .. close
end
return p