ผลต่างระหว่างรุ่นของ "มอดูล:Expand wikitext"

จากวิกิพีเดีย สารานุกรมเสรี
เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
Ans (คุย | ส่วนร่วม)
+parentPreprocessDecodeUnstrip
Ans (คุย | ส่วนร่วม)
.
บรรทัด 21: บรรทัด 21:
function p.preprocessDecodeUnstrip(frame)
function p.preprocessDecodeUnstrip(frame)
return frame:preprocess(mw.text.decode(mw.text.unstripNoWiki(frame.args[1])))
return frame:preprocess(mw.text.decode(mw.text.unstripNoWiki(frame.args[1])))
-- From experiment in https://th.wikisource.org/wiki/มอดูล:User:Ans/PerformanceTest
-- by function preprocessNowiki2M() vs preprocessNowikiM(),
-- this make code run faster?
--local text = mw.text
--return frame:preprocess(text.decode(text.unstripNoWiki(frame.args[1])))
end
end
-- To be invoked by Template
-- To be invoked by Template

รุ่นแก้ไขเมื่อ 19:17, 24 กันยายน 2564

Documentation icon คู่มือการใช้งานมอดูล[ดู] [แก้] [ประวัติ] [ล้างแคช]

การใช้งาน

{{#invoke:Expand wikitext|function_name}}

ตัวอย่าง

  • {{#invoke:expand wikitext|main|<nowiki>{{1x|x}}-</nowiki>}} → {{1x|x}}-
  • {{#invoke:expand wikitext|main|<nowiki>{{1x|x}} -</nowiki>}} → x -
  • {{#invoke:expand wikitext|main|<nowiki><u>u</u><ref>text</ref></nowiki>}} → <u>u</u><ref>text</ref>
  • {{#invoke:Expand wikitext|preprocessDecodeUnstrip|<nowiki>{{1x|x}}-</nowiki>}} → x-
  • {{#invoke:Expand wikitext|preprocessDecodeUnstrip|<nowiki>{{1x|x}} -</nowiki>}} → x -
  • {{#invoke:Expand wikitext|preprocessDecodeUnstrip|<nowiki><u>underline</u><ref>text</ref></nowiki>}}underline[1]

  1. 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)
	return frame:preprocess(mw.text.decode(mw.text.unstripNoWiki(frame.args[1])))
	-- From experiment in https://th.wikisource.org/wiki/มอดูล:User:Ans/PerformanceTest
	-- by function preprocessNowiki2M() vs preprocessNowikiM(),
	-- 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])))
end

return p