That is, the return value should be the *contents* of the extension tag and any *attributes* of the extension tag, not a wikitext string. (Right now we return the wikitext string starting with the open-extension tag and ending with the closed-extension-tag, leaving the extension to implement all escaping itself... often poorly or incompletely.)
The API should allow extensions to specify whether they prefer empty contents to be serialized as <tag></tag> or <tag/> or even perhaps <tag>\n</tag> (for "block" tags), but also whether they would like the tag to be dropped entirely (ex: Cite's <ref> tag has this behavior).
This is a follow up to https://gerrit.wikimedia.org/r/584052