Content deleted Content added
m spacing |
No edit summary |
||
Line 23:
-- and prepend s1 to the returned string
local letterpos
if mw.ustring.find(s, "^%[%[[^|]+|[^%]]+%]%]") then▼
local first_text = mw.ustring.match (s, '^%[%[[^%]]+%]%]'); -- extract
-- this is a piped wikilink, so we capitalise the text, not the pipe▼
local _▼
_, letterpos = mw.ustring.find(s, "|%W*%w") -- find the first letter after the pipe▼
local prefix, upcased;
if mw.ustring.match (first_text, "^%[%[[^|]+|[^%]]+%]%]") then -- if <first_text> is a piped link
prefix, upcased = mw.ustring.match (s, '^(%[%[[^|]+|)(%W*%w)'); -- get '[[<link text>|' and first letter
upcased = mw.ustring.upper (upcased); -- upcase first letter
s = mw.ustring.gsub (s, '^(%[%[[^|]+|)(%W*%w)', '%1' .. upcased); -- replace
else -- here when a wikilink but not a piped link
prefix, upcased = mw.ustring.match (s, '^(%[%[)(%W*%w)'); -- get '[[' and first letter
upcased = mw.ustring.upper (upcased); -- upcase first letter
s = mw.ustring.gsub (s, '^(%[%[)(%W*%w)', '%1' .. upcased); -- replace
elseif mw.ustring.match (s, '^%[[^%]]+%]') then -- if the first text is a ext link of some sort
first_text = mw.ustring.match (s, '^%[[^%]]+%]'); -- get the first text
prefix, upcased = mw.ustring.match (s, '^(%[%S+%s+)(%W*%w)'); -- get '[<url><space>' and first letter
upcased = mw.ustring.upper (upcased); -- upcase first letter
s = mw.ustring.gsub (s, '^(%[%S+%s+)(%W*%w)', '%1' .. upcased); -- replace
else
upcased = mw.ustring.upper (upcased); -- upcase first letter
▲ end
s = mw.ustring.gsub (s, '^(%W*%w)', upcased); -- replace
▲ if letterpos then
local first = mw.ustring.sub(s, 1, letterpos - 1)▼
local letter = mw.ustring.sub(s, letterpos, letterpos)▼
local rest = mw.ustring.sub(s, letterpos + 1)▼
return s1 .. first .. mw.ustring.upper(letter) .. rest▼
else▼
return s1 .. s▼
end
return s1 .. s; -- reattach initial list markup (if present)
▲-- -- this is a piped wikilink, so we capitalise the text, not the pipe
▲-- local _
▲-- _, letterpos = mw.ustring.find(s, "|%W*%w") -- find the first letter after the pipe
-- letterpos = mw.ustring.find(s, '%w')
-- end
-- if letterpos then
▲-- local first = mw.ustring.sub(s, 1, letterpos - 1)
▲-- local letter = mw.ustring.sub(s, letterpos, letterpos)
▲-- local rest = mw.ustring.sub(s, letterpos + 1)
▲-- return s1 .. first .. mw.ustring.upper(letter) .. rest
-- else
▲-- return s1 .. s
-- end
end
|