Module:Excerpt/sandbox: Difference between revisions

Content deleted Content added
Restore previous code for further testing
Undid revision 953910898 by Sophivorus (talk)
Line 494:
text = mw.ustring.gsub(text, "^.-<[Oo][Nn][Ll][Yy][Ii][Nn][Cc][Ll][Uu][Dd][Ee]>", "") -- remove text before first onlyinclude section
text = mw.ustring.gsub(text, "</[Oo][Nn][Ll][Yy][Ii][Nn][Cc][Ll][Uu][Dd][Ee]>.*", "") -- remove text after last onlyinclude section
end
if is(options.fragment) then
local escapedFragment = mw.ustring.gsub( options.fragment, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%0" )
local fragments = ""
local fragment = ""
local position = 1
while position < mw.ustring.len( text ) do
fragment, position = mw.ustring.match(text, "<%s*[Ss]ection%s+begin%s*=%s*[\"\']?%s*" .. escapedFragment .. "%s*[\"\']?%s*/>(.-)<%s*[Ss]ection%s+end=%s*[\"\']?%s*" .. escapedFragment .. "%s*[\"\']?%s*/>()", position )
if fragment and position then
fragments = fragments .. fragment
else
position = mw.ustring.len( text )
end
end
text = fragments
end
if not is(options.keepSubsections) then
Line 598 ⟶ 583:
pageName = pn or pageName
text, normalisedPageName = getContent(pageName)
if is(options.fragment) then
local frame = mw.getCurrentFrame()
text = frame:callParserFunction('#lst', normalisedPageName, options.fragment)
end
if not normalisedPageName then
return err("No title for page name " .. pageName)