Module:Template test case: Difference between revisions

    (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
    -- @TODO: Make HTML entities show up properly.
    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)
    obj.invocation = mw.text.unstrip(invocation)
    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. &amp;lt;, which is unfortunate,
    -- but it is the best we can do as the distinction between <, >, " and &lt;,
    -- &gt;, &quot; is lost during the original nowiki operation.
    invocation = invocation:gsub('&lt;', '<')
    invocation = invocation:gsub('&gt;', '>')
    invocation = invocation:gsub('&quot;', '"')
    -- Decode &amp; only when it is used to escape &lt;, &gt; and &quot;
    invocation = invocation:gsub('&amp;lt;', '&lt;')
    invocation = invocation:gsub('&amp;gt;', '&gt;')
    invocation = invocation:gsub('&amp;quot;', '&quot;')
    obj.invocation = invocation
    return obj
    return obj
    end
    end