How to prevent escaping table related tags outside of a table context

103 Views Asked by At

I am working on a Scribunto module that accepts a variable amount of arguments to produce a table. I have a template that invokes the module, and a separate template for the rows in the table. However, one of the components will always be outside of a table context, which in turn seem to escape <tr> and <td> tags.

the invoking template contains nothing but {{#invoke:Module|module}}

the row template contains the following example code:

|-
| {{{1}}}
| {{{2}}}

Any pages that uses this template includes it with

{{InvokeTemplate
| {{InvokeTemplate row | data1 | data2}}
}}

I tried creating the table in the lua module

args = frame:getParent().args
t = mw.create.html('table')
t
    :tag('tr')
        :tag('th')
            :wikitext('Header1')
        :tag('th')
            :wikitext('Header2')
    :wikitext(args[1])

return tostring(t)

At this point the row template was not in a table context, thus making the row template go unrendered. Then I tried using HTML in the row template, but the tags were translated to entities. Finally, I tried adding the table creation tags into the invoking template using {| and |}, and modifying the lua module to t = mw.create.html(), but while the row template tags was fine, the tags in the lua module were translated.

How do I prevent MediaWiki from translating these tags into html entities?

1

There are 1 best solutions below

0
On

In addition to what Kasper said: AFAIK your module should output wikitext, not HTML. Also, nested template invocation makes the whole thing quite fragile, probably compensating any gain produced by using Lua.

This invocation with explicit parameter would already be less fragile:

{{InvokeTemplate
|1= {{InvokeTemplate row | data1 | data2}}
}}

Better yet, usually people avoid nesting the templates at all and just do:

{{Table header}}
{{Table row | A | B }}
...
{{Table footer}}

Alternatively, if using Lua, you should make a template which passes an unlimited number of parameters to a module which produces wikitext for the entire table, header included.

But then from your example it's not clear at all why you need templates etc. to hide the table syntax, so it's harder to suggest a specific solution. https://meta.wikimedia.org/wiki/Help:Advanced_templates can help with many template quirks.