Difference between revisions of "Module:SandboxUString"
Jump to navigation
Jump to search
(19 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
rTable = { | |||
['<']='&-left', ['>']='&-right', | |||
['\\']='/',['\"']='*',['\'']='^' | |||
} | |||
function p.countChar(a) | function p.countChar(a) | ||
textLength = mw.ustring.len(mw.getCurrentFrame().args[1]) | textLength = mw.ustring.len(mw.getCurrentFrame().args[1]) | ||
Line 10: | Line 14: | ||
function p.showCode(a) | function p.showCode(a) | ||
str = " | |||
pageContent = | |||
str = "\\\"\'ABCDabc<>\\\"\'D"; | |||
return | return a:preprocess(str:gsub("%p", rTable)) | ||
end | |||
function p.htmlSourceCodeText(a) | |||
lTable = {} | |||
pageContent = mw.getCurrentFrame().args[1] | |||
local div = mw.html.create( 'syntaxhighlight' ) | |||
div | |||
:attr( 'lang', 'HTML' ) | |||
:wikitext( pageContent:gsub("%p", lTable)) | |||
return a:preprocess(tostring( div )) | |||
end | end | ||
function p.yamlSourceCodeText(a) | |||
lTable = {} | |||
pageContent = mw.getCurrentFrame().args[1] | |||
local div = mw.html.create( 'syntaxhighlight' ) | |||
div | |||
:attr( 'lang', 'YAML' ) | |||
:wikitext( pageContent:gsub("%p", lTable)) | |||
return a:preprocess(tostring( div )) | |||
end | |||
function p.luaSourceCodeText(a) | function p.luaSourceCodeText(a) | ||
pageContent = | lTable = {} | ||
pageContent = mw.getCurrentFrame().args[1] | |||
local div = mw.html.create( 'syntaxhighlight' ) | local div = mw.html.create( 'syntaxhighlight' ) | ||
div | div | ||
:attr( 'lang', 'lua' ) | :attr( 'lang', 'lua' ) | ||
:wikitext( " | :wikitext( pageContent:gsub("%p", lTable)) | ||
return a:preprocess(tostring( div )) | return a:preprocess(tostring( div )) | ||
end | end | ||
Line 41: | Line 67: | ||
end | end | ||
function p.gsub() | function p.gsub() | ||
return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\n' | return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\n' | ||
end | end | ||
return p | return p |
Latest revision as of 14:33, 11 January 2022
Documentation for this module may be created at Module:SandboxUString/doc
local p = {}
rTable = {
['<']='&-left', ['>']='&-right',
['\\']='/',['\"']='*',['\'']='^'
}
function p.countChar(a)
textLength = mw.ustring.len(mw.getCurrentFrame().args[1])
local div = mw.html.create( 'h1' )
div
:wikitext( "The number of characters is:" .. tostring(textLength) )
return a:preprocess(tostring( div ))
end
function p.showCode(a)
str = "\\\"\'ABCDabc<>\\\"\'D";
return a:preprocess(str:gsub("%p", rTable))
end
function p.htmlSourceCodeText(a)
lTable = {}
pageContent = mw.getCurrentFrame().args[1]
local div = mw.html.create( 'syntaxhighlight' )
div
:attr( 'lang', 'HTML' )
:wikitext( pageContent:gsub("%p", lTable))
return a:preprocess(tostring( div ))
end
function p.yamlSourceCodeText(a)
lTable = {}
pageContent = mw.getCurrentFrame().args[1]
local div = mw.html.create( 'syntaxhighlight' )
div
:attr( 'lang', 'YAML' )
:wikitext( pageContent:gsub("%p", lTable))
return a:preprocess(tostring( div ))
end
function p.luaSourceCodeText(a)
lTable = {}
pageContent = mw.getCurrentFrame().args[1]
local div = mw.html.create( 'syntaxhighlight' )
div
:attr( 'lang', 'lua' )
:wikitext( pageContent:gsub("%p", lTable))
return a:preprocess(tostring( div ))
end
function p.byte()
return ';byte\n:mw.ustring.byte(\'\\\') is ' .. mw.ustring.byte("\\") .. '\n'
end
function p.char()
return ';char\n:mw.ustring.char(92) is ' .. mw.ustring.char(92) .. '\n'
end
function p.codepoint()
return ';byte\n:mw.ustring.codepoint(\'张\') is ' .. mw.ustring.codepoint("张") .. '\n'
end
function p.ustringchar()
return ';byte\n:mw.ustring.char(24352) is ' .. mw.ustring.char(24352) .. '\n'
end
function p.gsub()
return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\n'
end
return p