Jump to content
Wikipedia The Free Encyclopedia

Module:Wikitext Parsing/doc

From Wikipedia, the free encyclopedia
icon This is a documentation subpage for Module:Wikitext Parsing.
It may contain usage information, categories and other content that is not part of the original module page.
Warning This Lua module is used on approximately 18,200,000 pages, or roughly 28% of all pages .
To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them.
This module can only be edited by administrators because it is transcluded onto one or more cascade-protected pages.

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

[edit ]
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.

PrepareText(text, keepComments) will run any content within certain tags that normally disable processing (<nowiki>, <pre>, <syntaxhighlight>, <source>, <math>) through mw.text.nowiki and remove HTML comments. This allows for tricky syntax to be parsed through more basic means such as %b{} by other modules without worrying about edge cases.

If the second parameter, keepComments, 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

[edit ]
This module is rated as alpha. It is ready for limited use and third-party feedback. It may be used on a small number of pages, but should be monitored closely. Suggestions for new features or adjustments to input and output are welcome.

ParseTemplates(InputText, dontEscape) will attempt to parse all {{Templates}} on a page, handling multiple factors such as [[Wikilinks]] and {{{Variables}}} 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
  • ArgOrder: A list of keys in the order they appear in the template
  • Children: A list of template objects that are contained within the existing template, in order of appearance. Only immediate children are listed
  • Name: The name of the template
  • Text: The raw text of the template

If the second parameter, dontEscape, is set to true, the inputted text won't be ran through the PrepareText function.


AltStyle によって変換されたページ (->オリジナル) /