跳转到内容

模組:Special wikitext

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

这是本页的一个历史版本,由A2569875留言 | 贡献2021年4月27日 (二) 14:04 (https://t.me/wikipedia_zh_n/1352478)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)

local p={}
function p.check()
	local file_name = mw.title.getCurrentTitle().fullText
	local file_name_spilt = mw.text.split(file_name, "%.")
	local file_ext = file_name_spilt[#file_name_spilt]
	if #file_name_spilt < 2 then return '' end
	if mw.ustring.lower(file_ext) == 'json' then
		return p.getJSONwikitext()
	elseif mw.ustring.lower(file_ext) == 'js' then
		return p.getJSwikitext()
	elseif mw.ustring.lower(file_ext) == 'css' then
		return p.getCSSwikitext()
	end
end
function p.getCSSwikitext()
	local this_frame = mw.getCurrentFrame()
	local wikitext = ''
	xpcall( function()
		local css_data = mw.title.getCurrentTitle():getContent()
		local it=mw.ustring.gmatch(css_data, "_addText%s*%{[^c%}]*content%s*:%s*[\"\'][^\n]*")
		local text=it()
		while text do
			wikitext = wikitext .. '\n' .. mw.ustring.sub(mw.ustring.gsub(mw.text.trim(
				mw.ustring.match(text,"content%s*:%s*[\"\'][^\n]*"), "\t\r\n\f ;}"
			),"%s*content%s*:%s*",""),2,-2)
			text=it()
		end
	end, function()end )
	return this_frame:preprocess(wikitext)
end
function p.getJSwikitext()
	local this_frame = mw.getCurrentFrame()
	local wikitext = ''
	xpcall( function()
		local js_data = mw.title.getCurrentTitle():getContent()
		local it=mw.ustring.gmatch(js_data, "_addText%s*%=%s*[\"\'][^\n]*")
		local text=it()
		while text do
			wikitext = wikitext .. '\n' .. mw.ustring.sub(mw.ustring.gsub(
				mw.text.trim(text, "\t\r\n\f ;}"),
			"_addText%s*%=%s*",""),2,-2)
			text=it()
		end
	end, function()end )
	return this_frame:preprocess(wikitext)
end
function p.getJSONwikitext()
	local this_frame = mw.getCurrentFrame()
	local wikitext = ''
	xpcall( function()
		local json_data = mw.text.jsonDecode(mw.title.getCurrentTitle():getContent())
		for k,v in pairs(json_data) do 
			if k == '_addText' and type(v) == type('')then
				wikitext = wikitext .. '\n' .. v
			end
			if v._addText and type(v._addText) == type('')then
				wikitext = wikitext .. '\n' ..v._addText
			end
		end
	end, function()end )
	return this_frame:preprocess(wikitext)
end
return p