UsageEdit

{{#invoke:Sandbox/Luis150902/cleanup|main|string}}, where string is the string to be escaped. This eases the editing of wiki markup containing bidirectional text. Inserting = (escaped form of =) is displayed as ;61#& between right-to-left characters.



-- This module escapes Unicode characters >= U+0100.

local p = {}

function p._main(s)
	local r = ""
	local i = 1
	local l = mw.ustring.len(s)
	local e = ""
	while i <= l do
	  if mw.ustring.codepoint(s, i) >= 256 then
	  	e = mw.ustring.format("&#x%04x;", mw.ustring.codepoint(s, i))
	  else
	  	e = mw.ustring.sub(s, i, i + 1)
	  end
	  r = r .. e
	  i = i + 1
	end
	return r
end

function p.main(frame)
    return p._main(frame.args[1])
end

return p