Module:Sandbox/User:Ans/Expand wikitext
(Redirected from Module:User:Ans/Expand wikitext)
Examples
edit{{#invoke:Sandbox/User:Ans/Expand wikitext|main|<nowiki>{{1x|x}}-</nowiki>}}→ {{1x|x}}-{{#invoke:Sandbox/User:Ans/Expand wikitext|main|<nowiki>{{1x|x}} -</nowiki>}}→ x -{{#invoke:Sandbox/User:Ans/Expand wikitext|main|<nowiki><u>u</u><ref>text</ref></nowiki>}}→ <u>u</u><ref>text</ref>{{#invoke:Sandbox/User:Ans/Expand wikitext|preprocessDecodeUnstrip|<nowiki>{{1x|x}}-</nowiki>}}→ x-{{#invoke:Sandbox/User:Ans/Expand wikitext|preprocessDecodeUnstrip|<nowiki>{{1x|x}} -</nowiki>}}→ x -{{#invoke:Sandbox/User:Ans/Expand wikitext|preprocessDecodeUnstrip|<nowiki><u>underline</u><ref>text</ref></nowiki></nowiki>}}→ underline[1]</nowiki>{{#invoke:Sandbox/User:Ans/Expand wikitext|preprocessUnstrip|<nowiki><u>underline</u><ref>text</ref></nowiki></nowiki>}}→ <u>underline</u><ref>text</ref></nowiki>
{{#invoke:Sandbox/User:Ans/Expand wikitext|preprocessDecodeUnstrip|ep=123|<nowiki>{{<!---->{ep}}}={{{ep}}}, {{<!---->{ep}}}+1={{#expr:{{{ep}}}+1}}, {{<!---->{2}}}={{{2}}}</nowiki>|abc}}→ {{{ep}}}=123, {{{ep}}}+1=124, {{{2}}}=abc
- ^ text
local p = {}
local yesno = require("Module:Yesno")
function p.main(frame)
local pframe = frame:getParent()
local code = frame.args[1]
if mw.text.trim(mw.text.killMarkers(code)) == "" or yesno(frame.args.unstrip) then
code = mw.text.unstripNoWiki(code);
end
return pframe:preprocess(code)
end
-- just in case we need to use {{{unstrip}}} in wikitext
-- also this make the code simpler and faster
function p.preprocess(frame)
return frame:preprocess(frame.args[1])
end
function p.preprocessUnstrip(frame)
return frame:preprocess(mw.text.unstripNoWiki(frame.args[1]))
end
-- To be invoked directly
function p.preprocessDecodeUnstrip(frame)
-- Need decode(), since mw.text.unstripNoWiki(frame.args[1]) under
-- {{#invoke:Expand wikitext|preprocessDecodeUnstrip|<nowiki><u>underline</u><ref>text</ref></nowiki></nowiki>}}
-- return "<u>underline</u><ref>text</ref></nowiki>"
--return frame:preprocess(mw.text.decode(mw.text.unstripNoWiki(frame.args[1])))
-- From experiment in https://test.wikipedia.org/w/index.php?title=Module_talk:User:Ans/performance_test/preprocessDecodeUnstrip&action=edit and https://test.wikipedia.org/w/index.php?title=Module_talk:User:Ans/performance_test/preprocessDecodeUnstrip2&action=edit
-- this make code run faster
local text = mw.text
return frame:preprocess(text.decode(text.unstripNoWiki(frame.args[1])))
end
-- To be invoked by Template
function p.parentPreprocessDecodeUnstrip(frame)
--return frame:getParent():preprocess(mw.text.decode(mw.text.unstripNoWiki(frame.args[1])))
local text = mw.text
return frame:getParent():preprocess(text.decode(text.unstripNoWiki(frame.args[1])))
end
function p.preprocessDecode(frame)
return frame:preprocess(mw.text.decode(frame.args[1]))
end
-- Pre-expanded text with HTML entities decoded, suitable for used in {{#tag:syntaxhighlight|...}}
function p.decodeUnstrip(frame)
local text = mw.text
return text.decode(text.unstripNoWiki(frame.args[1]))
end
return p