local export = {};
local data = require("Module:RQ:mxi:Kharja/data");
local function quote_section(title, kharja_index, section_index, lang)
local kharja = data;
local section = kharja.sections;
local bold = {};
local function rm_brackets(str)
return str:gsub('^%$', '');
end
local bracket_regex = '%';
local function strip_diacritics(str)
-- TODO: for now just Arabic
return str
:gsub('', '')
:gsub('ے', 'ی')
:gsub('ن', 'ࢽ');
end
local i = 1;
local text = mw.ustring.gsub(section.text, bracket_regex, function (str)
str = rm_brackets(str);
if (str:find(':')) then
local new_str = str:gsub(':.+', '');
if (strip_diacritics(str:gsub('.+:', '')) == title) then
str = "'''"..new_str.."'''";
bold = true;
else
str = new_str;
end
elseif (strip_diacritics(str) == title) then
str = "'''"..str.."'''";
bold = true;
end
i = i + 1;
return str;
end);
local function bold_with_colon(str)
str = rm_brackets(str);
if (str:find(':')) then
local new_str = str:gsub(':.+', '');
if (bold) then
str = "'''"..new_str.."'''";
else
str = new_str;
end
elseif (bold) then
str = "'''"..str.."'''";
end
i = i + 1;
return str;
end
local function bold_no_colon(str)
str = rm_brackets(str);
if (bold) then
str = "'''"..str.."'''";
end
i = i + 1;
return str;
end
local norm;
if (section.norm) then
i = 1;
norm = mw.ustring.gsub(section.norm, bracket_regex, bold_with_colon);
end
local tr = require('Module:mxi-translit').tr(norm or text, 'mxi', ({ A = 'Arab', H = 'Hebr' }));
tr = tr:gsub('{', ]):gsub('}', ]);
text = mw.ustring.gsub(text, '', '');
if (norm) then norm = mw.ustring.gsub(norm, '', ''); end
local ts;
if (section.ts) then
i = 1;
ts = mw.ustring.gsub(section.ts, bracket_regex, bold_no_colon);
end
local t;
if (section.t) then
i = 1;
t = mw.ustring.gsub(section.t, bracket_regex, bold_with_colon);
end
local lit;
if (section.lit) then
i = 1;
lit = mw.ustring.gsub(section.lit, bracket_regex, bold_with_colon);
end
return {
title = "quote-book",
args = {
'mxi',
termlang = lang,
year = kharja.year or 'c. 1100',
author = kharja.author,
title = ']',
section = section_index,
norm = norm, text = text, tr = tr, ts = ts, t = t, lit = lit,
}
};
end
function export.main(frame)
local args = frame:getParent().args;
local title = args.title or mw.title.getCurrentTitle().text;
local ret = '';
local first = true;
for i, v in ipairs(args) do
ret = ret .. frame:expandTemplate(quote_section(title, v:gsub('%..+', ''), tonumber((v:gsub('.+%.', ''))), args.lang));
if (first) then first = false;
else ret = '\n#*'..ret; end
end
return ret;
end
return export;