Module:Demo/sandbox explained

local p = local yn = require('Module:Yesno')local getArgs = require('Module:Arguments').getArgs-- simple module that takes in an input and displays the input and output of a wikitext-- helper function which gets all the locations of all the matches of a ustringfunction p._getAllMatchIndices(text, pattern) local output = local i = 0 while i ~= nil do i = mw.ustring.find(text, pattern, i + 1) if i ~= nil then table.insert(output, i) end end return outputend

-- replaces all usages of \[, \], \<, \> \\, \ with [, ], <, >, \, -- also replaces line breaks, carriage returns, and tabs with their appropriate characterfunction p._escapeAllCharacters(text) local indices = p._getAllMatchIndices(text, "\\") local splitText = mw.text.split(text, ) local skip = false for k,v in ipairs(indices) do if not skip then splitText[v] = local nc = splitText[v + 1] splitText[v + 1] = (nc

"e" and '=' or nc

"p" and '|' or nc

'[' and mw.getCurrentFrame:preprocess('<nowiki>[</nowiki>') or nc == ']' and mw.getCurrentFrame:preprocess(']') or nc

'