跳转到内容

模組:Special wikitext/Custom Module

本页使用了标题或全文手工转换
被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由A2569875留言 | 贡献2024年1月6日 (六) 06:19编辑。这可能和当前版本存在着巨大的差异。

#include <string>
std::string main () {
	std::string wikitext = mw::title::new("Template:Special wikitext/Custom Module")->getContent()
	mw::frame *frame = mw::getCurrentFrame()
	return frame->preprocess(wikitext)
}

local p = {}
require('Module:Module wikitext')._addText([[
{{#ifexpr:{{{_is_in_doc|0}}}=0|
{{Special wikitext/Hide Code}}
{{Special wikitext/Hide Doc}}
<div class="special-wikitext-not-hide">
{{#invoke:documentation|main|_is_in_doc={{#expr:{{{_is_in_doc|0}}}+1}}|_content={{ {{#invoke:documentation|contentTitle}}}}}}
<syntaxhighlight lang=cpp line>
#include <string>
std::string main () {
	std::string wikitext = mw::title::new("Template:Special wikitext/Custom Module")->getContent()
	mw::frame *frame = mw::getCurrentFrame()
	return frame->preprocess(wikitext)
}
</syntaxhighlight>
</div>
}}
]])
function p.main()
	local wikitext = mw.title.new("Template:Special wikitext/Custom Module"):getContent()
	--關於noinclude、includeonly和onlyinclude的regexp
	local empty_string = ""
	local re_noinclude_head = "<%s*[Nn][Oo][Ii][Nn][Cc][Ll][Uu][Dd][Ee]%s*>"
	local re_noinclude_tail = "<%s*/%s*[Nn][Oo][Ii][Nn][Cc][Ll][Uu][Dd][Ee]%s*>"
	local re_noinclude = "<%s*/?%s*[Nn][Oo][Ii][Nn][Cc][Ll][Uu][Dd][Ee]%s*/?%s*>"
	local re_includeonly = "<%s*/?%s*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][Oo][Nn][Ll][Yy]%s*/?%s*>"
	local re_onlyinclude = "<%s*/?%s*[Oo][Nn][Ll][Yy][Ii][Nn][Cc][Ll][Uu][Dd][Ee]%s*/?%s*>"
	local re_removes = {{"noinclude",re_noinclude}, {"includeonly",re_includeonly}, {"onlyinclude",re_onlyinclude}}
	--摘除模板樣板中的noinclude與當中的內容
	local noinclude = mw.ustring.find(wikitext, re_noinclude_head)
	local _i = 1
	while noinclude do --如果找到<noinclude>
		--尋找</noinclude>
		local _, noinclude_end = mw.ustring.find(wikitext, re_noinclude_tail)
		--如無</noinclude>,視為noinclude到頁面結尾
		noinclude_end = noinclude_end or -1
		--去除掉<noinclude>...</noinclude>與其之間的內容
		wikitext = mw.ustring.sub(wikitext, 1, noinclude-1) .. ((noinclude_end < 0) and empty_string or mw.ustring.sub(wikitext, noinclude_end + 1, -1))
		--尋找下一個<noinclude>
		noinclude = mw.ustring.find(wikitext, re_noinclude_head)
		_i = _i + 1 --避免無窮迴圈
		if _i > 100 then mw.addWarning(module_warn..'<noinclude>過多') break end
	end --<noinclude></noinclude>內容移除完畢
	local frame = mw.getCurrentFrame()
	return frame:preprocess(wikitext)
end
return p