Difference between revisions of "Demo:CodeWrapper"

From PKC
Jump to navigation Jump to search
Line 12: Line 12:


=Use returnHTMLText function=
=Use returnHTMLText function=
One may also use [[Lua]] to trim the textual content of the given input string:
One may also use [[Lua]] to attach marker (<code><nowiki><syntaxhighlight lang=html></nowiki></code>) and preprocess the textual content of the given input string:
Original source code:
Original source code:
  <nowiki> {{#invoke:CodeWrapper| returnHTMLText | {{:Demo:SwitchStatement7}}  }}</nowiki>
  <nowiki> {{#invoke:CodeWrapper| returnHTMLText | {{:Demo:SwitchStatement7}}  }}</nowiki>
This MediaWiki code(wiki text) will be rendered as follow:
This MediaWiki code(wiki text) will be rendered as follow:
  {{#invoke:CodeWrapper| returnHTMLText | {{:Demo:SwitchStatement7}}  }}
  {{#invoke:CodeWrapper| returnHTMLText | {{:Demo:SwitchStatement7}}  }}
=Use luaSourceCodeText function=
One may also use [[Lua]] to trim the textual content of the given input string:
Original source code:
<nowiki> {{#invoke:CodeWrapper| luaSourceCodeText | {{:Module:Banana}}  }}</nowiki>
This MediaWiki code(wiki text) will be rendered as follow:
{{#invoke:CodeWrapper| luaSourceCodeText | {{:Module:Banana}}  }}


=Use transclusion=
=Use transclusion=
In fact, if one tries to [[transclude]] a MediaWiki page in its original textual form without having MediaWiki parser parsing and interpreting the wiki code. One can do the following:
In fact, if one tries to [[transclude]] a MediaWiki page in its original textual form without having MediaWiki parser parsing and interpreting the wiki code. One can do the following:
  {{#invoke:CodeWrapper|originalText|{{:Demo:SwitchStatement7}}}}
  {{#invoke:CodeWrapper|originalText|{{:Demo:SwitchStatement7}}}}

Revision as of 15:40, 18 May 2022

This page shows how to include some page in its original form, without passing through the MediaWiki parser.

For example the following code segment {{:Demo:SwitchStatement7}} would render a a result like following:

{{#switch: {{#expr: 3+2*1}}
 | 1 = one
 | 2 = two
 | 3|4|5 = any of 3–5
 | 6 = six
 | 7 = {{uc:sEveN}} <!--lowercase-->
 | #default = other
}}


Use unstripNoWiki text

One may also use Lua to trim the textual content of the given input string: Original source code:

 {{#invoke:CodeWrapper| unstrip | {{:Demo:SwitchStatement7}}  }}

This MediaWiki code(wiki text) will be rendered as follow:

 any of 3–5


Use returnHTMLText function

One may also use Lua to attach marker (<syntaxhighlight lang=html>) and preprocess the textual content of the given input string: Original source code:

 {{#invoke:CodeWrapper| returnHTMLText | {{:Demo:SwitchStatement7}}  }}

This MediaWiki code(wiki text) will be rendered as follow:

 {{#switch: {{#expr: 3+2*1}}
 | 1 = one
 | 2 = two
 | 3|4|5 = any of 3–5
 | 6 = six
 | 7 = {{uc:sEveN}} &lt;!--lowercase--&gt;
 | #default = other
}}

Use luaSourceCodeText function

One may also use Lua to trim the textual content of the given input string: Original source code:

 {{#invoke:CodeWrapper| luaSourceCodeText | {{:Module:Banana}}  }}

This MediaWiki code(wiki text) will be rendered as follow:

 local p = {} --p stands for package

function p.hello( frame )
    --return "Hello, world!"
    return frame
end

return p

Use transclusion

In fact, if one tries to transclude a MediaWiki page in its original textual form without having MediaWiki parser parsing and interpreting the wiki code. One can do the following:

{{#switch: {{#expr: 3+2*1}}
 | 1 = one
 | 2 = two
 | 3|4|5 = any of 3–5
 | 6 = six
 | 7 = {{uc:sEveN}} <!--lowercase-->
 | #default = other
}}