Search code examples
mediawikiwikimarkupwikipediawikitext

How can I convert Wikitext Markup containing the double curly bracket functions, into plaintext or html?


I am creating a customized Wiki Markup parser/interpreter. There is a big task however in regards to interpreting functions like these:

{{convert|500|ft|m|0}}

which is converted like so:

500 feet (152 m)    

I'd like to avoid having to manually code interpretations of these functions, and would rather employ a method where I query a string

+akiva@akiva-ThinkPad-X230:~$ wiki-to-text "convert|3|to(-)|6|ft|abbr=on}}"

and get a return of:

"3 to 6 ft (0.91–1.83 m)"

Is there a tool to do this? Offline is by far the most ideal solution, but I could live with having to query a server.


Solution

  • You could query the MediaWiki api to get a parsed text from wikitext. E.g. to parse the template Template:Done from the english wikipedia you could use: https://en.wikipedia.org/w/api.php?action=parse&text={{Template:done}}&title=Test (see the online docs for parse). You, however, need a MediaWiki instance that provides a template that you want to parse and which works in the exact same way. If you install a webserver locally, you can install your own MediaWiki instance and parse wikitext locally, too.

    Btw.: There's the Parsoid project, too, which implements a node-based wikitext->html->wikitext parser. However, it, iirc, still needs to query the api of the wiki to parse templates.