Module:Chabad Days: Difference between revisions
Strip footnotes from box lines |
Footer link as a button; button() for box button rows |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 19: | Line 19: | ||
local function cleanLine(line) | local function cleanLine(line) | ||
line = line:gsub('<ref[^>]-/>', ''):gsub('<ref.-</ref>', '') | line = line:gsub('<ref[^>]-/>', ''):gsub('<ref.-</ref>', '') | ||
-- "5587 (10/12/1826 by the [[Gentile Calendar|secular count]]) - text" -> "[[5587]] (1826) | -- "5587 (10/12/1826 by the [[Gentile Calendar|secular count]]) - text" -> "[[5587]] (1826) - Text" | ||
local b1, year, b2, paren, b3, text = line:match("^%*+%s*('*)(%d%d%d%d)('*)%s*%((.-)%)%s*('*)%s*%-%s*(.*)$") | local b1, year, b2, paren, b3, text = line:match("^%*+%s*('*)(%d%d%d%d)('*)%s*%((.-)%)%s*('*)%s*%-%s*(.*)$") | ||
if not year then | if not year then | ||
| Line 29: | Line 29: | ||
if greg then out = out .. ' (' .. greg .. ')' end | if greg then out = out .. ' (' .. greg .. ')' end | ||
return out, b3 .. ucfirstText(text) | return out, b3 .. ucfirstText(text) | ||
end | |||
function p._button(target, pageName, year) | |||
return '<span style="display:inline-block; padding:0.25em 0.9em; border:1px solid #a2a9b1; border-radius:4px; background:#ffffff;">[[' .. | |||
target .. '#Chabad Days|' .. pageName .. ' ' .. year .. ' - More on this day]]</span>' | |||
end | |||
-- button only, for use in a box's button row | |||
function p.button(frame) | |||
local day = frame:callParserFunction('#time', 'xjj') | |||
local month = frame:callParserFunction('#time', 'xjF') | |||
month = MONTHS[month] or month | |||
local pageName = day .. ' ' .. month | |||
local title = mw.title.new(pageName) | |||
if not (title and title.exists) then return '' end | |||
if title.isRedirect and title.redirectTarget then title = title.redirectTarget end | |||
return p._button(title.fullText, pageName, frame:callParserFunction('#time', 'xjY')) | |||
end | end | ||
| Line 53: | Line 70: | ||
content:match('\n==%s*Chabad Days%s*==%s*\n(.*)$') | content:match('\n==%s*Chabad Days%s*==%s*\n(.*)$') | ||
if section then | if section then | ||
section = section:gsub('<ref[^>]-/>', ''):gsub('<ref.-</ref>', '') | |||
local prefix = '' | local prefix = '' | ||
for line in (section .. '\n'):gmatch('(.-)\n') do | for line in (section .. '\n'):gmatch('(.-)\n') do | ||
| Line 66: | Line 84: | ||
local head2, text = cleanLine(line) | local head2, text = cleanLine(line) | ||
if text then | if text then | ||
table.insert(out, head2 .. ' | table.insert(out, head2 .. ' - ' .. prefix .. text) | ||
else | else | ||
table.insert(out, head2) | table.insert(out, head2) | ||
| Line 81: | Line 99: | ||
end | end | ||
local year = frame:callParserFunction('#time', 'xjY') | local year = frame:callParserFunction('#time', 'xjY') | ||
local footer = '<div style="clear:both; text-align:right; margin-top:0.4em;">' .. | local target = content and title.fullText or nil | ||
local footer = '' | |||
if args.button ~= 'no' and target then | |||
footer = '<div style="clear:both; text-align:right; margin-top:0.4em;">' .. p._button(target, pageName, year) .. '</div>' | |||
end | |||
return '<div style="text-align:justify;">\n' .. body .. '\n</div>\n' .. footer | return '<div style="text-align:justify;">\n' .. body .. '\n</div>\n' .. footer | ||
end | end | ||
return p | return p | ||