Parses all occurences of a Mediawiki Template from Mediawiki text
From npm.js:
npm install --save parse-mediawiki-template
From Github:
git clone https://github.com/plepe/parse-mediawiki-template
cd parse-mediawiki-template
npm install
With script tag in the browser:
<script src="https://cdn.jsdelivr.net/npm/parse-mediawiki-template@0.2.2/dist/parse-mediawiki-template.umd.js"></script>
The function will parse wikitext (parameter 1) and find all occurences of the specified template (parameter 2). Mediawiki text is case insensitive.
The result is an array with an entry for each occurence. If the template has parameters, it will list them.
import parseMediawikiTemplate from 'parse-mediawiki-template';
const wikitext = 'Page content {{Template|param1|foo=paramFoo}} {{OtherTemplate}} {{Template|second|occurence}}';
const template = 'template';
const result = parseMediawikiTemplate(wikitext, template);
result is:
[
{
"1": "param1",
"foo": "paramFoo"
},
{
"1": "second",
"2": "occurence"
}
]
- Stephan Bösch-Plepelits (initial code)
- Lenni009 (port to TypeScript)