Is there an existing Javascript library (outside VisualEditor etc.) for parsing the TemplateData format
syntax? Wanted for TemplateWizard (task T186653). @cscott: are you someone to ask about this?
Topic on Extension talk:TemplateData
The implementation in Parsoid starts around here:
https://github.com/wikimedia/parsoid/blob/master/lib/html2wt/WikitextSerializer.js#L510
and the specification is
I think the entirety of the parser is basically this:
var FORMATSTRING_REGEXP = /^(\n)?(\{\{ *_+)(\n? *\|\n? *_+ *= *)(_+)(\n? *\}\})(\n)?$/; var formatStringSubst = function(format, value, forceTrim) { if (forceTrim) { value = value.trim(); } return format.replace(/_+/, function(hole) { if (value === '' || hole.length <= value.length) { return value; } return value + (' '.repeat(hole.length - value.length)); }); };
Thanks! That's brilliant info. :)