jenkins-bot has submitted this change and it was merged.

Change subject: (Bug 57252) Generate HTML5-compliant cite id/about attr values
......................................................................


(Bug 57252) Generate HTML5-compliant cite id/about attr values

* Currently, this mimics Cite.php behavior where "a b" and "a_b"
  are considered identical ids.

* Added new parser test.
* Fixed output of another test.
* Fixed section name of a commented out test.

Change-Id: I0c51404c3e659bbddfe9a8909aa6a109d368b762
---
M lib/ext.Cite.js
M tests/parserTests.txt
2 files changed, 28 insertions(+), 4 deletions(-)

Approvals:
  Arlolra: Looks good to me, but someone else must approve
  Marcoil: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/ext.Cite.js b/lib/ext.Cite.js
index 993a64c..bd54427 100644
--- a/lib/ext.Cite.js
+++ b/lib/ext.Cite.js
@@ -150,8 +150,16 @@
        this.indexByName = new Map();
 }
 
-RefGroup.prototype.add = function( references, refName, about, skipLinkback ) {
+function makeValidIdAttr(val) {
+       // Looks like Cite.php doesn't try to fix ids that already have
+       // a "_" in them. Ex: name="a b" and name="a_b" are considered
+       // identical. Not sure if this is a feature or a bug.
+       return val.replace(/\s/g, '_');
+}
+
+RefGroup.prototype.add = function(references, refName, about, skipLinkback) {
        var ref;
+       refName = makeValidIdAttr(refName);
        if ( refName && this.indexByName.has( refName ) ) {
                ref = this.indexByName.get( refName );
        } else {
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 8dfb4dd..85510a4 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -19400,6 +19400,22 @@
 !!end
 
 !!test
+Ref: 17. Generate valid HTML5 id/about attributes
+!!options
+parsoid
+!!wikitext
+<ref name="a b">foo</ref>
+
+<references />
+!!html
+<p><span class="reference" id="cite_ref-a_b-1-0" rel="dc:references" 
typeof="mw:Extension/ref" 
data-mw='{"name":"ref","body":{"html":"foo"},"attrs":{"name":"a b"}}'><a 
href="#cite_note-a_b-1">[1]</a></span>
+</p>
+
+<ol class="references" typeof="mw:Extension/references" 
data-mw='{"name":"references","attrs":{}}'>
+<li id="cite_note-a_b-1"><span rel="mw:referencedBy"><a 
href="#cite_ref-a_b-1-0">↑</a></span> foo</li>
+!!end
+
+!!test
 References: 1. references tag without any refs should be handled properly
 !!options
 parsoid
@@ -19536,7 +19552,7 @@
 !! wikitext
 <ref name="test &amp; me">hi</ref>
 !! html
-<p><span about="#mwt2" class="reference" id="cite_ref-test &amp; me-1-0" 
rel="dc:references" typeof="mw:Extension/ref" data-parsoid='{"src":"&lt;ref 
name=\"test &amp;amp; me\">hi&lt;/ref>"}' 
data-mw='{"name":"ref","body":{"html":"hi"},"attrs":{"name":"test &amp; 
me"}}'><a href="#cite_note-test &amp; me-1">[1]</a></span></p>
+<p><span about="#mwt2" class="reference" id="cite_ref-test_&amp;_me-1-0" 
rel="dc:references" typeof="mw:Extension/ref" data-parsoid='{"src":"&lt;ref 
name=\"test &amp;amp; me\">hi&lt;/ref>"}' 
data-mw='{"name":"ref","body":{"html":"hi"},"attrs":{"name":"test &amp; 
me"}}'><a href="#cite_note-test_&amp;_me-1">[1]</a></span></p>
 !! end
 
 # This test is wt2html only because we're permitting the serializer to produce
@@ -21693,9 +21709,9 @@
 #!! options
 #parsoid=html2wt
 #language=ar
-#!! input
+#!! wikitext
 #[[Imagen:Foobar.jpg|derecha|miniaturadeimagen]]
-#!! result
+#!! html
 #<figure class="mw-default-size mw-halign-right" typeof="mw:Image/Thumb"><a 
href="Imagen:Foobar.jpg"><img resource="./Imagen:Foobar.jpg" 
src="//example.com/images/3/3a/Foobar.jpg" height="20" 
width="180"/></a></figure>
 #!! end
 

-- 
To view, visit https://gerrit.wikimedia.org/r/105406
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0c51404c3e659bbddfe9a8909aa6a109d368b762
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Marcoil <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to