Module:Excerpt/sandbox: Difference between revisions

Content deleted Content added
Check for empty keepSubsections or keepRefs
Define truthy() function to test for truthy values
Line 65:
if errors then error(text, 2) end
return ""
end
 
local function truthy( value )
if not value or value == "" or value == "0" or value == "false" or value == "no" then
return false
end
return true
end
 
Line 472 ⟶ 479:
t = t .. token -- keep wanted block templates
 
elseif truthy(options.keepTables) and mw.ustring.sub(token, 1, 2) == '{|' then
t = t .. token -- keep tables
 
Line 533 ⟶ 540:
local function cleanupText(text, keepSubsections, keepRefs)
text = mw.ustring.gsub(text, "<!%-%-.-%-%->","") -- remove HTML comments
if not truthy(keepSubsections or keepSubsections == "") then
text = mw.ustring.gsub(text, "\n==.*","") -- remove first ==Heading== and everything after it
text = mw.ustring.gsub(text, "^==.*","") -- ...even if the lead is empty
Line 543 ⟶ 550:
text = mw.ustring.gsub(text, "</[Oo][Nn][Ll][Yy][Ii][Nn][Cc][Ll][Uu][Dd][Ee]>.*", "") -- remove text after last onlyinclude section
end
if not truthy(keepRefs or keepRefs == "") then
text = mw.ustring.gsub(text, "<%s*[Rr][Ee][Ff][^>]-/%s*>", "") -- remove refs cited elsewhere
text = mw.ustring.gsub(text, "<%s*[Rr][Ee][Ff].->.-<%s*/%s*[Rr][Ee][Ff]%s*>", "") -- remove refs