Module:Calendar TOC: Difference between revisions

Content deleted Content added
Undid revision 1036121117 by Frietjes (talk)
remove format support: no one was using the hlist version; some code style adjustments in the main function
 
(3 intermediate revisions by the same user not shown)
Line 21:
local res = {}
 
table.insert(res, '__NOTOC__<table role="navigation" id="toc" class="calendar-toc wikitable toc hlist" style="text-align:center">')
table.insert(res, '<tr><th colspan=7 id="toctitle" style="background:inherit"><span id="tocheading" style="font-weight:bold">' .. month .. ' ' .. year .. '</span></th></tr>')
table.insert(res, '<tr><th scope="col">' .. table.concat(weekdays, '</th><th scope="col">') .. '</th></tr>')
 
Line 75:
return table.concat(res, '\n')
end
 
local function listtoc(founddays, days, unk, footer, month)
local starttxt = [[
__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;">
]]
local closetxt = [[</div></div>]]
local entries = (#founddays > 0) and { ';' .. month} or {}
for k,d in ipairs(founddays) do
local fmt = days[d]
if fmt == 'df' then
table.insert(entries, ': [[#' .. d .. ' ' .. month .. '|' .. d .. ']]')
elseif fmt == 'mf' then
table.insert(entries, ': [[#' .. month .. ' ' .. d .. '|' .. d .. ']]')
end
end
if unk ~= nil then
table.insert(entries, ': [[#' .. unk .. '|' .. unk .. ']]')
end
for k,v in ipairs(footer) do
table.insert(entries, ': [[#' .. v .. '|' .. v .. ']]')
end
return starttxt .. table.concat(entries,"\n") .. closetxt
end
 
Line 143 ⟶ 117:
local pargs = frame:getParent().args
local current_title = mw.title.getCurrentTitle()
local pagename = current_title.text
local content = current_title:getContent()
local outfmt = args['format'] or pargs['format'] or ''
local unknown = nil
if args['_demo'] or pargs['_demo'] then
Line 160 ⟶ 131:
 
-- Get the month and year
local pagename = current_title.text
local month = getMonth(pagename, args['month'] or pargs['month'] or '')
local year = getYear(pagename, args['year'] or pargs['year'] or '')
Line 180 ⟶ 152:
local founddays = {}
local footer = {}
local starttxtunknown = [[nil
for v in mw.ustring.gmatch(content, "%f[^\n]==%s*([^\r\n]-)%s*==%f[^=]") do
v = mw.ustring.gsub(v,'^[=%s]*(.-)[%s=]*', '%1')
Line 197 ⟶ 170:
end
 
return caltoc(days, unknown, footer, month, year)
-- Now generate the TOC
if outfmt ~= 'list' then
return caltoc(days, unknown, footer, month, year)
end
 
return listtoc(founddays, days, unknown, footer, month)
end