Content deleted Content added
No edit summary |
remove format support: no one was using the hlist version; some code style adjustments in the main function |
||
(16 intermediate revisions by 5 users not shown) | |||
Line 15:
end
local function caltoc(days, unk, footer, month, year)
local weekdays = {'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'}
local j = tonumber(formatDate('N','1 ' .. month .. ' ' .. year))
Line 21:
local res = {}
table.insert(res, '__NOTOC__<table role="navigation" id="toc" class="calendar-toc wikitable toc
table.insert(res, '<tr><th colspan=7
table.insert(res, '<tr><th scope="col">' .. table.concat(weekdays, '</th><th scope="col">') .. '</th></tr>')
local d = 1-j
local skip = false
while d <= N do
table.insert(res, '<tr>')
Line 39 ⟶ 40:
table.insert(res, '<td>' .. d .. '</td>')
end
local cs = (d <= 0) and (1 - d) or (8 - i)
if d > N and cs > 2 and unk then
unk = nil
end▼
table.insert(
end
skip = true
end
end
table.insert(res, '</tr>')
end
end▼
if #footer > 0 then
table.insert(res, '<tr
end▼
table.insert(res, '</td>')
else
table.insert(res, '<td colspan=7>[[#' .. table.concat(footer,'') .. '|' .. table.concat(footer,'') .. ']]</td>')
end
table.insert(res, '</
▲ table.insert(res, '</td></tr>')
end
table.insert(res, '</table>')
return table.concat(res, '\n')
▲end
local starttxt = [[▼
▲ 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
▲ for k,v in ipairs(footer) do
▲ table.insert(entries, ': [[#' .. v .. '|' .. v .. ']]')
end▼
end
Line 122 ⟶ 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 ''▼
if args['_demo'] or pargs['_demo'] then
▲ end
if not content then
error "The current page has no content"
end
-- Remove comments
content = mw.ustring.gsub(content, '<!--.-?-->', '')
-- 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 140 ⟶ 141:
footerlinks = mw.text.split(extra, '%s*=%s*')
else
footerlinks = {
end
local validfooter = {}
Line 151 ⟶ 152:
local founddays = {}
local footer = {}
for v in mw.ustring.gmatch(content, "%f[^\n]==%s*([^\r\n]-)%s*==%f[^=]") do
v = mw.ustring.gsub(v,'^[=%s]*(.-)[%s=]*', '%1')
Line 161 ⟶ 163:
days[df] = 'mf'
table.insert(founddays, mf)
unknown = "Unknown date"
elseif validfooter[v] then
table.insert(footer, v)
Line 166 ⟶ 170:
end
▲ if outfmt ~= 'list' then
▲ return caltoc(days, footer, month, year)
end
|