Module:Excerpt: Difference between revisions

Content deleted Content added
m Restore line removed accidentally in previous edit
Remove unmatched {{ etc. which might break an enclosing template such as {{#tag:gallery}}
Line 534:
end, 1) -- "end" here terminates the anonymous replacement function(a, b) passed to gsub
end
 
-- Seek and destroy unterminated templates and wikilinks
repeat -- hide matched {{template}}s including nested templates
local t = text
text = mw.ustring.gsub(text, "{(%b{})}", "{\27%1\27}"); -- {{sometemplate}} → {E{sometemplate}E} where E represents escape
until text == t
repeat -- do similar for [[wikilink]]s
local t = text
text = mw.ustring.gsub(text, "%[(%b[])%]", "[\27%1\27]");
until text == t
text = text.gsub(text, "([{}%[%]])%1.*", ""); -- remove unmatched {{, }}, [[ or ]] and everything thereafter
text = mw.ustring.gsub(text, "\27", ""); -- unhide matched pairs: {E{ → {{, ]E] → ]], etc.
 
if options.more then text = text .. " '''[[" .. pagename .. "|" .. options.more .. "]]'''" end -- wikilink to article for more info