Module:WikitextParser/doc
Appearance
![]() | This is a documentation subpage for Module:WikitextParser. It may contain usage information, categories and other content that is not part of the original module page. |
This module is a general-purpose wikitext parser. It's designed to be used by other Lua modules and cannot be called directly by templates.
Usage
First, require WikitextParser and get some wikitext to parse. For example:
local parser = require( 'Module:WikitextParser' )
local title = mw.title.getCurrentTitle()
local wikitext = title:getContent()
Then, use and combine the available methods freely:
getLead( wikitext )
— Get the lead section from the given wikitext. The lead section is defined as everything before the first section. Returns the wikitext of the lead section. May be empty if there's no lead section.getSections( wikitext )
— Get all the sections from the given wikitext. Returns a map from section title to section content. This method doesn't get the lead section, usegetLead
for that.getSection( wikitext, title )
— Returns the content of the section with the given title from the given wikitext. Includes subsections. If the given section title appears more than once, only the first one will be returned.
See also
- Module:Excerpt - Main caller of this module
- mw:WikitextParser.js - Similar parser written in JavaScript, for use in gadgets, user scripts and other tools