2

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.

Anon
  • 2,267
  • 3
  • 34
  • 51
  • Best way to parse locally: https://en.wikipedia.org/wiki/Wikipedia:TemplateData – John Strood Apr 15 '19 at 11:05
  • @JohnStrood Hmmm... Interesting. On my end, I have a local mediawiki, and ended up programming my own parser that can do varied types of interpretations. https://git.launchpad.net/qconsoledesigner/tree/qmediawiki.cpp if you are interested in a local implementation. (Although it is admittedly catered specifically for my purposes.) – Anon Apr 15 '19 at 11:48

1 Answers1

5

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.

Florian
  • 2,796
  • 1
  • 15
  • 25