Module:Excerpt: Difference between revisions

Content deleted Content added
add IPA needed
Use match instead of find, to capture the current string position with ()
Line 181:
for position, altText in mw.ustring.gmatch(text, "|%s*[Aa][Ll][Tt]%s*=%s*()([^\n]*)") do
if altText then
 
-- altText is terminated by }} or |, but first skip any matched [[...]] and {{...}}
local lookfrom = math.max( -- find position after whichever comes last: start of string, end of last ]] or end of last }}
mw.ustring.findmatch(altText, ".*{%b{}}()") or 1, -- if multiple {{...}}, .* consumes all but one, leaving the last for %b
mw.ustring.findmatch(altText, ".*%[%b[]%]()") or 1)
 
local len = mw.ustring.len(altText)
local aftertext = math.min( -- find position after whichever comes first: end of string, }} or |
mw.ustring.findmatch(altText, "()}}", lookfrom) or len+1,
mw.ustring.findmatch(altText, "()|", lookfrom) or len+1)
altText = mw.ustring.sub(altText, 1, aftertext-1) -- chop off |... or }}... which is not part of [[...]] or {{...}}
 
Line 558 ⟶ 559:
text = mw.ustring.gsub(text, "%[(%b[])%]", "\27[\27%1\27]\27");
until text == t
 
text = text.gsub(text, "([{}%[%]])%1[^\27].*", ""); -- remove unmatched {{, }}, [[ or ]] and everything thereafter, avoiding ]E]]E] etc.
text = mw.ustring.gsub(text, "\27", ""); -- unhide matched pairs: E{E{ → {{, ]E]E → ]], etc.