Module:WikitextParser/doc: Difference between revisions

Content deleted Content added
Start documenting
 
No edit summary
Line 13:
</syntaxhighlight>
 
Then, use and combine the available methods freely. For example:
 
<syntaxhighlight lang="lua">
* <code>getLead( wikitext )</code> — 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.
local files = parser.getFiles( wikitext )
* <code>getSections( wikitext )</code> — 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 <code>getLead</code> for that.
for file in files do
* <code>getSection( wikitext, title )</code> — 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.
-- Do stuff
end
</syntaxhighlight>
 
Here's a list of available methods:
 
* <code>getLead( wikitext )</code> — GetReturns the lead section from the given wikitext. The lead section is defined as everything before the first section. Returns the wikitext of the lead sectiontitle. May be empty if there's no lead section.
* <code>getSections( wikitext )</code> — Get allReturns the sections from the given wikitext., Returnsas a mapLua fromtable with the section titletitles toas keys and the section content as values. This method doesn't get the lead section, (use <code>getLead</code> for that).
* <code>getSection( wikitext, title )</code> — 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. If the section is not found, nil will be returned.
 
For the ultimate documentation, see the source code below.
 
== See also ==