Module:Wikitext Parsing/doc: Difference between revisions

Wiki>Aidan9382
some adjustments
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{High risk}}
{{cascade-protected template|page=module}}
This module provides some functions to help with the complex edge cases involved in modules like [[Module:Template parameter value]] which intend to process the raw wikitext of a page while respecting nowiki tags or similar content reliably. This module is designed to be called by other modules, and does not support invoking.
== PrepareText ==
{{Module rating|release}}
<code>PrepareText(text, keepComments)</code> will run any content within certain tags that normally disable processing ({{tag|nowiki|o}}, {{tag|pre|o}}, {{tag|syntaxhighlight|o}}, {{tag|source|o}}, {{tag|math|o}}) through mw.text.nowiki and remove HTML comments. This allows for tricky syntax to be parsed through more basic means such as <code>%b{}</code> by other modules without worrying about edge cases.
If the second parameter, <code>keepComments</code>, is set to true, the content of HTML comments will be passed through mw.text.nowiki instead of being removed entirely.
Any code using this function directly should consider using mw.text.decode to correct the output at the end if part of the processed text is returned, though this will also decode any input that was encoded but not inside a no-processing tag, which likely isn't a significant issue but still something worth noting.
== ParseTemplates ==
== ParseTemplates ==
{{Module rating|alpha}}
{{Module rating|alpha}}
<code>ParseTemplates(InputText, dontEscape)</code> will attempt to parse all <code><nowiki>{{Templates}}</nowiki></code> on a page, handling multiple factors such as <code><nowiki>[[Wikilinks]]</nowiki></code> and <code><nowiki>{{{Variables}}}</nowiki></code> among other complex syntax. Due to the complexity of the function, it is considerably slow, and should be used carefully. The function returns a list of template objects in order of appearance, which have the following properties:
<code>ParseTemplates(InputText, dontEscape)</code> will attempt to parse all <code><nowiki>{{Templates}}</nowiki></code> on a page, handling multiple factors such as <code><nowiki></nowiki></code> and <code><nowiki>{{{Variables}}}</nowiki></code> among other complex syntax. Due to the complexity of the function, it is considerably slow, and should be used carefully. The function returns a list of template objects in order of appearance, which have the following properties:
* '''Args''': A key-value set of arguments, not in order
* '''Args''': A key-value set of arguments, not in order
* '''ArgOrder''': A list of keys in the order they appear in the template
* '''ArgOrder''': A list of keys in the order they appear in the template