Difference between revisions of "Demo:CodeWrapper"
(30 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
This page shows how to include some page in its original form, without passing through the MediaWiki parser. | This page shows how to include some page in its original form, without passing through the MediaWiki parser. The main idea of why this example is important can be found in this article: [[A computable framework for accountable data assets]]<ref>[[Ben Koo]], [[A computable framework for accountable data assets]]</ref>. | ||
For example the following code segment would render a | For example the following code segment <code><nowiki>{{:Demo:SwitchStatement7}}</nowiki></code> would render a a result like following: | ||
<nowiki>{{:Demo:SwitchStatement7}}</nowiki> | {{:Demo:SwitchStatement7}} | ||
=Use unstripNoWiki text= | |||
One may also use [[Lua]] to trim the textual content of the given input string: | |||
Original source code: | |||
<nowiki> {{#invoke:CodeWrapper| unstrip | {{:Demo:SwitchStatement7}} }}</nowiki> | |||
This MediaWiki code(wiki text) will be rendered as follow: | |||
{{#invoke:CodeWrapper| unstrip | {{:Demo:SwitchStatement7}} }} | |||
=Use returnHTMLText function= | |||
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: | |||
<nowiki> {{#invoke:CodeWrapper| returnHTMLText | {{:Demo:SwitchStatement7}} }}</nowiki> | |||
This MediaWiki code(wiki text) will be rendered as follow: | |||
{{#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 reverseResult Function= | |||
In fact, if one needs to string.reverse function of [[Lua]] library. One can do the following: | |||
<nowiki>{{#invoke:CodeWrapper|returnHTMLText|{{#invoke:CodeWrapper|reverseResult|{{:Module:Banana}}}} }}</nowiki> | |||
The rendered page segment looks like follows: | |||
{{#invoke:CodeWrapper|returnHTMLText|{{#invoke:CodeWrapper|reverseResult|{{:Module:Banana}}}} }} | |||
=Some configurable results= | |||
{| class="wikitable" | |||
|- | |||
! Wiki Source Code !! Rendered Result | |||
|- | |||
| | |||
{{#invoke:CodeWrapper| returnDecodedText |{{:Demo:IfExpr1}} }} | |||
|| | |||
{{#invoke:CodeWrapper| unstrip |{{:Demo:IfExpr1}} }} | |||
|- | |||
| | |||
{{#invoke:CodeWrapper| returnDecodedText |{{:Demo:IfExpr2}} }} | |||
|| | |||
{{#invoke:CodeWrapper| unstrip |{{:Demo:IfExpr2}} }} | |||
|} | |||
<noinclude> | |||
=References= | |||
<references/> | |||
=Related Pages= | |||
[[Category:Lua]] | |||
[[Category:Scribunto]] | |||
</noinclude> |
Latest revision as of 02:24, 19 May 2022
This page shows how to include some page in its original form, without passing through the MediaWiki parser. The main idea of why this example is important can be found in this article: A computable framework for accountable data assets[1].
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}} <!--lowercase-->
| #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 reverseResult Function
In fact, if one needs to string.reverse function of Lua library. One can do the following:
{{#invoke:CodeWrapper|returnHTMLText|{{#invoke:CodeWrapper|reverseResult|{{:Module:Banana}}}} }}
The rendered page segment looks like follows:
p nruter
dne
emarf nruter
"!dlrow ,olleH" nruter--
) emarf (olleh.p noitcnuf
egakcap rof sdnats p-- }{ = p lacol
Some configurable results
Wiki Source Code | Rendered Result |
---|---|
'''Wrapper wikicode or text''' {{#ifexpr: 3<5 | This expression is {{#expr: 0=0}} | This expression is evaluated to {{#expr: 9>9}} }} '''Wrapper wikicode'''. |
Wrapper wikicode or text This expression is 1 Wrapper wikicode. |
{{#ifexpr: 7=3 | {{#expr: 3+2=5}} RESULT | some text representing {{#expr: 1<1}} result }} |
some text representing 0 result |