Jump to content

Module:Calendar TOC and Module:Calendar TOC/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
remove format support: no one was using the hlist version; some code style adjustments in the main function
 
clean
 
Line 22: Line 22:


table.insert(res, '__NOTOC__<table role="navigation" id="toc" class="calendar-toc wikitable toc" style="text-align:center">')
table.insert(res, '__NOTOC__<table role="navigation" id="toc" class="calendar-toc wikitable toc" style="text-align:center">')
table.insert(res, '<tr><th colspan=7 style="background:inherit"><span style="font-weight:bold">' .. month .. ' ' .. year .. '</span></th></tr>')
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>')
table.insert(res, '<tr><th scope="col">' .. table.concat(weekdays, '</th><th scope="col">') .. '</th></tr>')


Line 75: Line 75:
return table.concat(res, '\n')
return table.concat(res, '\n')
end

local function listtoc(founddays, days, unk, footer, month)
local starttxt = [[
__NOTOC__<!--
--><div role="navigation" id="toc" class="calendar-toc 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
end


Line 117: Line 143:
local pargs = frame:getParent().args
local pargs = frame:getParent().args
local current_title = mw.title.getCurrentTitle()
local current_title = mw.title.getCurrentTitle()
local pagename = current_title.text
local content = current_title:getContent()
local content = current_title:getContent()
local outfmt = args['format'] or pargs['format'] or ''
local unknown = nil
if args['_demo'] or pargs['_demo'] then
if args['_demo'] or pargs['_demo'] then
Line 131: Line 160:


-- Get the month and year
-- Get the month and year
local pagename = current_title.text
local month = getMonth(pagename, args['month'] or pargs['month'] or '')
local month = getMonth(pagename, args['month'] or pargs['month'] or '')
local year = getYear(pagename, args['year'] or pargs['year'] or '')
local year = getYear(pagename, args['year'] or pargs['year'] or '')
Line 152: Line 180:
local founddays = {}
local founddays = {}
local footer = {}
local footer = {}
local unknown = nil
for v in mw.ustring.gmatch(content, "%f[^\n]==%s*([^\r\n]-)%s*==%f[^=]") do
for v in mw.ustring.gmatch(content, "%f[^\n]==%s*([^\r\n]-)%s*==%f[^=]") do
v = mw.ustring.gsub(v,'^[=%s]*(.-)[%s=]*', '%1')
v = mw.ustring.gsub(v,'^[=%s]*(.-)[%s=]*', '%1')
Line 170: Line 197:
end
end


-- Now generate the TOC
return caltoc(days, unknown, footer, month, year)
if outfmt ~= 'list' then
return caltoc(days, unknown, footer, month, year)
end

return listtoc(founddays, days, unknown, footer, month)
end
end