Module:Special wikitext
Appearance
Documentation for this module may be created at Module:Special wikitext/doc
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