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) – text"
-- "5587 (10/12/1826 by the [[Gentile Calendar|secular count]]) - text"  ->  "[[5587]] (1826) – Text"
line = line:gsub("^(%*+)%s*('*)(%d%d%d%d)('*)%s*%(%d+/%d+/(%d+)[^%)]*%)%s*('*)%s*%-%s*",
local b1, year, b2, paren, b3, text = line:match("^%*+%s*('*)(%d%d%d%d)('*)%s*%((.-)%)%s*('*)%s*%-%s*(.*)$")
function(stars, b1, year, b2, greg, b3)
if not year then
return '* ' .. b1 .. '[[' .. year .. ']]' .. b2 .. ' (' .. greg .. ') ' .. b3 .. '– '
b1, year, b2, b3, text = line:match("^%*+%s*('*)(%d%d%d%d)('*)%s*('*)%s*%-%s*(.*)$")
end)
end
line = line:gsub("^(%*+)%s*('*)(%d%d%d%d)('*)%s*%-%s*", '* %2[[%3]]%4 – ')
if not year then return line end
return line
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 l = cleanLine(line)
local head2, text = cleanLine(line)
if prefix ~= '' then
if text then
l = l:gsub(' – ', ' – ' .. prefix, 1)
table.insert(out, head2 .. ' – ' .. prefix .. text)
else
table.insert(out, head2)
end
end
table.insert(out, l)
end
end
end
end