We would like to build a smarter wikitext editor with (for example) smart template/infobox collapsing.
But parsing wikitext on the client is a losing proposition.
Let's do something similar to the [sections API](http://restbase.wikimedia.org/en.wikipedia.org/v1/?doc#resource_Mobile) (T94890) used by mobile to deliver a full JSON description of the structure of a given wikitext revision. It should include wikitext offsets for:
- The start/end of sections
- The start/end of templates (and their names, so that certain templates can be identified for special treatment)
- The start/end of extension tags (and the extension name)
- what else? links? media, for contextual popovers?
As a strawman, the result could look like:
{ sections: [ 0, 10, 50, 70], templates: [ ['foo', 10, 14], ['infobox', 17, 23] ], media: [ ['Foobar.jpg', 10, 17] ], extensions: { gallery: [ [ 40, 45], [60, 65] ] } }
The wikitext editor can use these source offsets to collapse regions of wikitext by default to allow a cleaner editing experience.
To go further, perhaps we should export source offsets for things like bold face, italics, and links to allow the wikitext editor to do syntax highlighting? (Or not -- perhaps syntax highlighting is best done with imperfect-but-okay regexps on the client side.)