Modul:Italic title: Unterschied zwischen den Versionen

added support for string= in italic dab; fixed edge cases where module failed. All changes tested at Module talk:Italic title/testcases. Ping if you encounter an issue
(replace with an object-based framework, and add a dabonly function for Template:Italic dab)
(added support for string= in italic dab; fixed edge cases where module failed. All changes tested at Module talk:Italic title/testcases. Ping if you encounter an issue)
Zeile 82: Zeile 82:
prefix, parentheses = mw.ustring.match(
prefix, parentheses = mw.ustring.match(
title.text,
title.text,
'^(.+) %(([^%(%)]+)%)$'
'^(.+) (%b())$'
)
)
end
end
if parentheses then
parentheses = parentheses:sub(2, -2)
end
if prefix and parentheses then
if prefix and parentheses then
self.title = prefix
self.title = prefix
Zeile 197: Zeile 202:
-- italicization of the main part of the title.
-- italicization of the main part of the title.
if next(italicizedSubstrings) then
if next(italicizedSubstrings) then
titleParts.title = self.title
local originalString
if titleParts.dab then
originalString = self.dab
else
originalString = self.title
end
for s in pairs(italicizedSubstrings) do
for s in pairs(italicizedSubstrings) do
local pattern = escapeMagicCharacters(s)
local pattern = escapeMagicCharacters(s)
local italicizedTitle, nReplacements = titleParts.title:gsub(
local italicizedTitle, nReplacements = originalString:gsub(
pattern,
pattern,
italicize
italicize
)
)
titleParts.title = italicizedTitle
if titleParts.dab then
titleParts.dab = italicizedTitle
else
titleParts.title = italicizedTitle
end


-- If we didn't make any replacements then it means that we
-- If we didn't make any replacements then it means that we
Zeile 294: Zeile 309:


function p._dabonly(args)
function p._dabonly(args)
return ItalicTitle.new()
local italicTitle = ItalicTitle.new()
:italicize('dab')
if args.string then
:render(args[1])
italicTitle:italicizeSubstring(args.string)
else
italicTitle:italicize('dab')
end
return italicTitle:render(args[1])
end
end


Anonymer Benutzer