Module:Template test case: Difference between revisions
decode lt, gt and quot HTML enties for NowikiInvocation objects, and escape HTML entities in pre tag invocations in Template objects
(Tweak Template:getInvocation to not escape things so enthusiastically. Still need to make HTML entities show up properly.) |
(decode lt, gt and quot HTML enties for NowikiInvocation objects, and escape HTML entities in pre tag invocations in Template objects) |
||
Line 111: | Line 111: | ||
else | else | ||
-- Default is pre tags | -- Default is pre tags | ||
invocation = mw.text.encode(invocation, '&') | |||
invocation = '<pre style="white-space: pre-wrap;">' .. invocation .. '</pre>' | invocation = '<pre style="white-space: pre-wrap;">' .. invocation .. '</pre>' | ||
invocation = mw.getCurrentFrame():preprocess(invocation) | invocation = mw.getCurrentFrame():preprocess(invocation) | ||
Line 316: | Line 316: | ||
function NowikiInvocation.new(invocation) | function NowikiInvocation.new(invocation) | ||
local obj = setmetatable({}, NowikiInvocation) | local obj = setmetatable({}, NowikiInvocation) | ||
invocation = mw.text.unstrip(invocation) | |||
-- Decode HTML entities for <, >, and ". This means that HTML entities in | |||
-- the original code must be escaped as e.g. &lt;, which is unfortunate, | |||
-- but it is the best we can do as the distinction between <, >, " and <, | |||
-- >, " is lost during the original nowiki operation. | |||
invocation = invocation:gsub('<', '<') | |||
invocation = invocation:gsub('>', '>') | |||
invocation = invocation:gsub('"', '"') | |||
-- Decode & only when it is used to escape <, > and " | |||
invocation = invocation:gsub('&lt;', '<') | |||
invocation = invocation:gsub('&gt;', '>') | |||
invocation = invocation:gsub('&quot;', '"') | |||
obj.invocation = invocation | |||
return obj | return obj | ||
end | end |