Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Auto compact TOC
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local start = [[ __NOTOC__<!-- --><div role="navigation" id="toc" class="toc plainlinks hlist" aria-labelledby="tocheading"> <div class="toctitle" style="text-align:center;"><span id="tocheading" style="font-weight:bold;">Contents</span></div> <div style="margin:auto;"> ]] local close = [[</div></div>]] local function make_TOC_item(anchor, link_text) link_text = link_text or anchor return ("* [[#%s|%s]]"):format(anchor, link_text) end local Array_mt = { __index = table } local function Array() return setmetatable({}, Array_mt) end function p.make_TOC(frame) local content = mw.title.getCurrentTitle():getContent() if not content then error "The current page has no content" end local letters = Array() -- 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(make_TOC_item(letter)) end local yesno = require "Module:Yesno" local rest = Array() local other_headers = require "Module:TableTools".listToSet{ "See also", "References", "Notes", "Further reading", "External links", } for header in content:gmatch "%f[^\n]==%s*(..-)%s*==%f[^=]" do if other_headers[header] then rest:insert(make_TOC_item(header)) end end return start .. letters:concat("\n") .. "\n\n" .. rest:concat("\n") .. close end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Sandbox other
(
edit
)
Template:Tl
(
edit
)
Module:Auto compact TOC/doc
(
edit
)
Module:String
(
edit
)