Module:Chabad Days: Difference between revisions
Module for the main-page Chabad Days box (per Hebrew תבנית:אירועים בלוח העברי) |
Handle year-only and bold lines; capitalize first word |
||
| Line 9: | Line 9: | ||
['Adar II'] = 'Adar', ['Heshvan'] = 'Cheshvan', ['Tishri'] = 'Tishrei', | ['Adar II'] = 'Adar', ['Heshvan'] = 'Cheshvan', ['Tishri'] = 'Tishrei', | ||
} | } | ||
local function ucfirstText(t) | |||
-- capitalize the first visible letter: "the X" -> "The X", "[[A|the X]]" -> "[[A|The X]]" | |||
local a, rest = t:match("^(%[%[[^|%]]*|)(.*)$") | |||
if a then return a .. rest:gsub('^%l', string.upper) end | |||
return (t:gsub('^%l', string.upper)) | |||
end | |||
local function cleanLine(line) | local function cleanLine(line) | ||
-- "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*(.*)$") | |||
if not year then | |||
b1, year, b2, b3, text = line:match("^%*+%s*('*)(%d%d%d%d)('*)%s*('*)%s*%-%s*(.*)$") | |||
end | |||
if not year then return line end | |||
return | local greg = paren and paren:match('.*(%d%d%d%d)') | ||
local out = '* ' .. b1 .. '[[' .. year .. ']]' .. b2 | |||
if greg then out = out .. ' (' .. greg .. ')' end | |||
return out, b3 .. ucfirstText(text) | |||
end | end | ||
| Line 48: | Line 58: | ||
else prefix = '' end | else prefix = '' end | ||
elseif line:match('^%*') then | elseif line:match('^%*') then | ||
local | local head2, text = cleanLine(line) | ||
if | if text then | ||
table.insert(out, head2 .. ' – ' .. prefix .. text) | |||
else | |||
table.insert(out, head2) | |||
end | end | ||
end | end | ||
end | end | ||