Page MenuHomePhabricator

Enable section collapsing for readers
Open, MediumPublic

Description

We want to run some DOM transformations which make it easier for clients to collapse and expand nested sections.
These DOM transformations should be performed server-side to avoid performance issues on clients.
Headers are added to make it easier for downstream services or client code to add section decorators (edit buttons, collapse/expand indicators, ...).

Simple proposal

<section>
  <header>
    <h2>Title</h2>
  </header>
  <div typeof="mw:SectionContent">
    <!-- Content -->
  </div>
</section>

Fuller example (nested + lead section)

<section data-mw-section-id=0>
  <div typeof="mw:SectionContent">
    <!-- Content of lead section -->
  </div>
</section>
<section data-mw-section-id=1>
  <header>
    <h2>Section 1</h2>
  </header>
  <div typeof="mw:SectionContent">
    <!-- Content of Section 1 -->
    <p>foo</p>
    <section data-mw-section-id=2>
      <header>
        <h3>Section 1.1</h3>
      </header>
      <div typeof="mw:SectionContent">
        <!-- Content of subsection Section 1.1 -->
      </div>
    </section>
  </div>
</section>

Event Timeline

Took examples from T176959 and expanded on them. There are more good discussions about the why, what, and how there. Please comment here to adjust the proposed DOM.

Note that in some scenarios, without additional work, this can break template wrapping semantics. See Example 2 in https://www.mediawiki.org/wiki/Parsing/Notes/Section_Wrapping#Examples and the commit message in my section wrapper patch ( https://gerrit.wikimedia.org/r/#/c/364933/32 ) for how even adding just the <section> tag can do this and how the section wrapping code handles this.

This is not a problem for you if you plan to strip all template information anyway. But, if the templating information is exposed in read views (or you plan to access template information in your own code after this transformation), you need to ensure that template wrapping semantics are preserved.