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. For example:
local sections = parser.getSections( wikitext )
for sectionTitle, sectionContent in pairs( sections ) do
local sectionFiles = parser.getFiles( sectionContent )
-- Do stuff
end
Here's a list of available methods:
getLead( wikitext )
— Returns the lead section from the given wikitext. The lead section is defined as everything before the first section title. May be empty if there's no lead section.getSections( wikitext )
— Returns the sections from the given wikitext, as a Lua table with the section titles as keys and the section content as values. This method doesn't get the lead section (usegetLead
for that).getSection( wikitext, title )
— Returns the content of the section with the given title, including subsections. If you don't want subsections, usegetSections
instead. If the given section title appears more than once, only the first will be returned. If the section is not found,nil
will be returned.
For the ultimate documentation, see the source code below.
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