Page MenuHomePhabricator

Make it possible to distinguish Wikitext headings and HTML headings
Closed, ResolvedPublicFeature

Description

Right now the HTML created for

  • headings specified using Wikitext (e.g. "==")
  • headings created using HTML tags (e.g. "<h2>")

look basically the same.

  • Both have a wrapping heading element (without class or id)
  • Both contain a <span> of class "mw-headline"

The only (but major) difference is that sections created by Wikitext are editable and therefore contain an additional <span> of class "mw-editsection".

It would be nice if there was an easy possibility to directly differentiate those types of headers on a CSS level (e.g. by an additional class applied to the parent <h*> element)

This would make it much easier to create custom CSS and JS since often one would only want to style "true" (that is editable) article headers created by Wikitext instead of custom created headers that are mostly used for design of e.g. project pages.
Right now such CSS and JS often erroneously styles all headers the same, regardless of how the headers were created, often resulting in unintentional appearance.


Version: 1.24rc
Severity: enhancement

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 3:12 AM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz66637.
bzimport added a subscriber: Unknown Object (MLST).
Aklapper changed the subtype of this task from "Task" to "Feature Request".Feb 4 2022, 11:13 AM
Aklapper removed a subscriber: wikibugs-l-list.

Change 990775 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@master] Add 'typeof="mw:Heading"' to wikitext headings

https://gerrit.wikimedia.org/r/990775

Change 990776 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/services/parsoid@master] Add 'typeof="mw:Heading"' to wikitext headings

https://gerrit.wikimedia.org/r/990776

Change 990777 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/VisualEditor@master] Allow 'typeof="mw:Heading"' on Parsoid headings

https://gerrit.wikimedia.org/r/990777

Change 990778 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/DiscussionTools@master] Detect HTML headings using 'typeof="mw:Heading"'

https://gerrit.wikimedia.org/r/990778

Change 990775 abandoned by Bartosz Dziewoński:

[mediawiki/core@master] Add 'typeof="mw:Heading"' to wikitext headings

Reason:

I'm not working on this at the moment.

https://gerrit.wikimedia.org/r/990775

Change 990776 abandoned by Bartosz Dziewoński:

[mediawiki/services/parsoid@master] Add 'typeof="mw:Heading"' to wikitext headings

Reason:

I'm not working on this at the moment.

https://gerrit.wikimedia.org/r/990776

Change 990777 abandoned by Bartosz Dziewoński:

[mediawiki/extensions/VisualEditor@master] Allow 'typeof="mw:Heading"' on Parsoid headings

Reason:

I'm not working on this at the moment.

https://gerrit.wikimedia.org/r/990777

Change 990778 abandoned by Bartosz Dziewoński:

[mediawiki/extensions/DiscussionTools@master] Detect HTML headings using 'typeof="mw:Heading"'

Reason:

I'm not working on this at the moment.

https://gerrit.wikimedia.org/r/990778

I forgot to note this here at the time, but I talked to some folks from the Content Transform team after I proposed these patches, who didn't like them very much because the semantic meaning of these attributes wasn't clear and it would also require changes to the Parsoid HTML spec with backwards-compat implications. Their counterproposal was adding some class name or some other attribute to only the "raw" HTML headings instead (internal Slack link: https://wikimedia.slack.com/archives/C024Z8K9CAU/p1705359054223579 – sorry, not publicly accessible). I'd be happy with that too, I just didn't get around to trying to implement it.

Substantially the same idea was also proposed in T13555#9896561 by @Od1n.

It does seem a bit strange though to simultaneously push for all media files to have a convoluted typeof-based syntax and for headings to not have typeof-based syntax. Though I do think that <figure> conversion as implemented was a massive mistake and we ended up with a lot of CSS bloat because of it that could’ve been avoided if classes were used, so I don’t have a problem with using them generally.

Change #1113861 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@master] OutputTransform: Mark HTML headings with class="mw-rawheading"

https://gerrit.wikimedia.org/r/1113861

Maybe we can try doing it like this. This patch uses a class instead of typeof. It's also much simpler and less risky by adding it in the output transform, rather than in the parser itself – the tradeoff is that we can't distinguish == … == from <h2>…</h2> (with no attributes), but maybe nobody really cares that much about that case? (nobody seemed to mind it much when the same thing came up in T353489).

the tradeoff is that we can't distinguish == … == from <h2>…</h2> (with no attributes)

While developing JavaScript gadgets, I have encountered the following needs regarding section headings:

  • Adding a link next to the title (the position to insert varies depending on whether it's a regular or raw heading, if the section has an "edit" link or not, what skin is used, if MobileFrontend is present or not…).
  • Getting the section's anchor (i.e., the value of the id attribute).
  • Getting the section's title.
  • Selecting the section content (essentially, all elements following the section heading, up to a stopping element: next section heading, navbox…), with the use case being a toggle to show/hide the content (more specifically, a blur effect to hide spoilers).

Additionally, there's a need to exclude the h2#mw-toc-heading element (as it would not have the mw-rawheading class, this issue would be resolved as well).

For these use cases, the code differs significantly depending on whether the headings are regular or raw, but we don't need to concern ourselves with what wikicode has been used. What's important is supporting both structures of outputted HTML. Thus, I would say the tradeoff you mentioned is not an issue.

(For additional context, you may see my comments starting from T13555#10040671)

Change #1113861 merged by jenkins-bot:

[mediawiki/core@master] OutputTransform: Mark HTML headings with class="mw-html-heading"

https://gerrit.wikimedia.org/r/1113861

The distinguishing class name has been merged, and it is called class="mw-html-heading". I documented this on the previous documentation page, please review: https://www.mediawiki.org/w/index.php?title=Heading_HTML_changes&diff=prev&oldid=7602007

matmarex claimed this task.