As a skin developer I would like to render the table of contents outside the parser content as part of the skin. This will support several use cases:
- Desktop Improvement Project : The ToC concept would require the ToC to be moved out of #mw-content-text
- Minerva/MobileFrontEnd: ToC is only accessible at the top of the article, which makes navigating long articles a pain point as there are no 'to the top' button and collapsing each section takes multiple interactions.
- Third-party skins: Skin authors want to be able to move the ToC but the current solution is very hacky. Citizen uses a lot of CSS hacks while Tweeki clone the whole DOM of #toc. Both solutions have a hefty penalty on the rendering path when it should be avoided.
To do this I would use a skin option inside skin.json toc which can have two values "html" or "data".
"ValidSkinNames": { "myskin": { "class": "SkinMustache", "args": [ { "name": "myskin", "toc": "data"
When data, the skin is instructed to disable output of the table of contents in the parser output via a publically method on OutputPage or getHTML method:
A new template key would be added for all skins. This data would be a structure that is Mustache-compatible and supports recursive rendering to support nesting.
'data-toc' => $this->getOutput()->getParserOutput()->getTableOfContentData()
Template:
{{#data-toc}} {{#items}}{{>Item}}{{/item}} {{/data-toc}}
Item <li><h{{level}}>{{headline}}</h{{level}}> <ul>{{#items}}{{>Item}}{{/item}}</ul> </li>
Related
T114057: Refactor table of contents
Acceptance criteria
- Skins can opt-out of including a table of contents in the HTML output by adding "toc": false to the skin declaration inside skin.json https://gerrit.wikimedia.org/r/c/mediawiki/core/+/735069
- Skins are provided with raw data allowing them to render a table of contents as they desire