Jump to content

Module:WikitextParser/doc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sophivorus (talk | contribs) at 22:56, 18 March 2025 (Start documenting). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)


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, use getLead 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