parse-mediawiki-template
v0.2.2
Published
Parses all occurences of a Mediawiki Template from Mediawiki text
Downloads
101
Readme
parse-mediawiki-template
Parses all occurences of a Mediawiki Template from Mediawiki text
INSTALLATION
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/[email protected]/dist/parse-mediawiki-template.umd.js"></script>
USAGE
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"
}
]
CONTRIBUTORS
- Stephan Bösch-Plepelits (initial code)
- Lenni009 (port to TypeScript)