Parsoid's templated content have other attrs as well

Bug: T372019
Change-Id: Ic1d32570f5fed4d48a126d0ef4c8c04a82d7bbb4
This commit is contained in:
Arlo Breault 2024-08-07 18:32:44 -04:00
parent 55665a3f93
commit 69fd71b260
6 changed files with 106 additions and 2 deletions

View file

@ -116,9 +116,13 @@ class CommentFormatter {
) ) {
// Do not add the wrapper if the heading has attributes generated from wikitext (T353489).
// Only allow reserved attributes (e.g. 'data-mw', which can't be used in wikitext, but which
// are used internally by our own code and by Parsoid) and the 'id' attribute used by Parsoid.
// are used internally by our own code and by Parsoid) and the 'id', 'about', and 'typeof'
// attributes used by Parsoid.
foreach ( $headingElement->attributes as $attr ) {
if ( $attr->name !== 'id' && !Sanitizer::isReservedDataAttribute( $attr->name ) ) {
if (
!in_array( $attr->name, [ 'id', 'about', 'typeof' ], true ) &&
!Sanitizer::isReservedDataAttribute( $attr->name )
) {
return $headingElement;
}
}

View file

@ -226,5 +226,17 @@
},
"config": "../data/enwiki-config.json",
"data": "../data/enwiki-data.json"
},
{
"name": "Heading with Parsoid template attributes",
"title": "Talk:Templated_heading",
"dom": "cases/heading-templated-parsoid/heading-templated-parsoid.html",
"expected": {
"legacy": "cases/heading-templated-parsoid/heading-templated-parsoid-formatted-legacy.html",
"desktop": "cases/heading-templated-parsoid/heading-templated-parsoid-formatted-desktop.html",
"mobile": "cases/heading-templated-parsoid/heading-templated-parsoid-formatted-mobile.html"
},
"config": "../data/enwiki-config.json",
"data": "../data/enwiki-data.json"
}
]

View file

@ -0,0 +1,28 @@
<section data-mw-section-id="0" id="mwAQ"></section><section data-mw-section-id="-1" id="mwAg"><div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Hello" data-mw-thread-id="h-Hello"><span data-mw-comment-start="" id="h-Hello"></span>Hello<span data-mw-comment-end="h-Hello"></span></h2></div>
</section><section data-mw-section-id="-1" id="mwAw"><div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Hi" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;Hi&quot;,&quot;href&quot;:&quot;./Template:Hi&quot;},&quot;params&quot;:{},&quot;i&quot;:0}}]}" about="#mwt1" data-mw-thread-id="h-Hi"><span data-mw-comment-start="" id="h-Hi"></span>Hi<span data-mw-comment-end="h-Hi"></span></h2></div></section>
<pre>
newestComment: null
{
"wgDiscussionToolsPageThreads": [
{
"headingLevel": 2,
"name": "h-",
"type": "heading",
"level": 0,
"id": "h-Hello",
"replies": [],
"uneditableSection": true
},
{
"headingLevel": 2,
"name": "h-",
"type": "heading",
"level": 0,
"id": "h-Hi",
"replies": [],
"uneditableSection": true
}
]
}
</pre>

View file

@ -0,0 +1,28 @@
<section data-mw-section-id="0" id="mwAQ"></section><section data-mw-section-id="-1" id="mwAg"><div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Hello" data-mw-thread-id="h-Hello"><span data-mw-comment-start="" id="h-Hello"></span>Hello<span data-mw-comment-end="h-Hello"></span></h2></div>
</section><section data-mw-section-id="-1" id="mwAw"><div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Hi" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;Hi&quot;,&quot;href&quot;:&quot;./Template:Hi&quot;},&quot;params&quot;:{},&quot;i&quot;:0}}]}" about="#mwt1" data-mw-thread-id="h-Hi"><span data-mw-comment-start="" id="h-Hi"></span>Hi<span data-mw-comment-end="h-Hi"></span></h2></div></section>
<pre>
newestComment: null
{
"wgDiscussionToolsPageThreads": [
{
"headingLevel": 2,
"name": "h-",
"type": "heading",
"level": 0,
"id": "h-Hello",
"replies": [],
"uneditableSection": true
},
{
"headingLevel": 2,
"name": "h-",
"type": "heading",
"level": 0,
"id": "h-Hi",
"replies": [],
"uneditableSection": true
}
]
}
</pre>

View file

@ -0,0 +1,28 @@
<section data-mw-section-id="0" id="mwAQ"></section><section data-mw-section-id="-1" id="mwAg"><div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Hello" data-mw-thread-id="h-Hello"><span data-mw-comment-start="" id="h-Hello"></span>Hello<span data-mw-comment-end="h-Hello"></span></h2></div>
</section><section data-mw-section-id="-1" id="mwAw"><div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Hi" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;Hi&quot;,&quot;href&quot;:&quot;./Template:Hi&quot;},&quot;params&quot;:{},&quot;i&quot;:0}}]}" about="#mwt1" data-mw-thread-id="h-Hi"><span data-mw-comment-start="" id="h-Hi"></span>Hi<span data-mw-comment-end="h-Hi"></span></h2></div></section>
<pre>
newestComment: null
{
"wgDiscussionToolsPageThreads": [
{
"headingLevel": 2,
"name": "h-",
"type": "heading",
"level": 0,
"id": "h-Hello",
"replies": [],
"uneditableSection": true
},
{
"headingLevel": 2,
"name": "h-",
"type": "heading",
"level": 0,
"id": "h-Hi",
"replies": [],
"uneditableSection": true
}
]
}
</pre>

View file

@ -0,0 +1,4 @@
<!DOCTYPE html>
<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost:3080/wiki/Special:Redirect/revision/6876"><head prefix="mwr: http://localhost:3080/wiki/Special:Redirect/"><meta charset="utf-8"/><meta property="mw:pageId" content="100067"/><meta property="mw:pageNamespace" content="0"/><link rel="dc:replaces" resource="mwr:revision/0"/><meta property="mw:revisionSHA1" content="56cf429d8ecfe7af0dd8dbcee99f0c4acb93920f"/><meta property="dc:modified" content="2023-12-15T21:52:39.000Z"/><meta property="mw:htmlVersion" content="2.8.0"/><meta property="mw:html:version" content="2.8.0"/><link rel="dc:isVersionOf" href="http://localhost:3080/wiki/Heading_with_styles"/><base href="http://localhost:3080/wiki/"/><title>Heading with styles</title><link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=mediawiki.skinning.content.parsoid%7Cmediawiki.skinning.interface%7Csite.styles&amp;only=styles&amp;skin=vector"/><meta http-equiv="content-language" content="en"/><meta http-equiv="vary" content="Accept"/></head><body id="mwAA" lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr"><section data-mw-section-id="0" id="mwAQ"></section><section data-mw-section-id="-1" id="mwAg"><h2 id="Hello">Hello</h2>
</section><section data-mw-section-id="-1" id="mwAw"><h2 id="Hi" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Hi","href":"./Template:Hi"},"params":{},"i":0}}]}' about="#mwt1">Hi</h2></section></body></html>