Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/222263
Change subject: Lineardoc: Do not skip tags with empty content but with
attributes
......................................................................
Lineardoc: Do not skip tags with empty content but with attributes
Those attributes are important and sometimes contain information for
parsoid to work with references or templates.
Added tests to verify lineardoc is not eating up empty tags
Bug: T104539
Change-Id: I4cca925cb35a00fa27fd31380fae90e1c4c2767f
---
M lineardoc/Builder.js
M tests/lineardoc/LinearDoc.test.js
A tests/lineardoc/data/test3-result.xhtml
A tests/lineardoc/data/test3-result.xml
A tests/lineardoc/data/test3.xhtml
5 files changed, 85 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver
refs/changes/63/222263/1
diff --git a/lineardoc/Builder.js b/lineardoc/Builder.js
index 15f806c..5df6a53 100644
--- a/lineardoc/Builder.js
+++ b/lineardoc/Builder.js
@@ -58,7 +58,11 @@
'Mismatched inline tags: open=' + ( tag && tag.name ) +
', close=' + tagName
);
}
- if ( tag.name !== 'span' || !tag.attributes[ 'data-mw' ] ) {
+
+ if ( !Object.keys( tag.attributes).length ) {
+ // if the tag has no attributes, we can safeley assume that
+ // we not check for empy/whitespace only tags. Otherwise, we
might be skipping
+ // important tags just because it has no content. See Bug
T104539
return tag;
}
// Check for empty/whitespace-only data span. Replace as inline content
diff --git a/tests/lineardoc/LinearDoc.test.js
b/tests/lineardoc/LinearDoc.test.js
index 745fb36..13a1007 100644
--- a/tests/lineardoc/LinearDoc.test.js
+++ b/tests/lineardoc/LinearDoc.test.js
@@ -6,7 +6,7 @@
QUnit.test( 'LinearDoc tests', function ( assert ) {
var parser, testXhtmlFile, resultXmlFile, resultXhtmlFile, testXhtml,
resultXml,
resultXhtml, i,
- numTests = 2;
+ numTests = 3;
QUnit.expect( 2 * numTests );
for ( i = 1; i <= numTests; i++ ) {
testXhtmlFile = __dirname + '/data/test' + i + '.xhtml';
diff --git a/tests/lineardoc/data/test3-result.xhtml
b/tests/lineardoc/data/test3-result.xhtml
new file mode 100644
index 0000000..d6ac7fa
--- /dev/null
+++ b/tests/lineardoc/data/test3-result.xhtml
@@ -0,0 +1,14 @@
+<html>
+<head>
+<meta charset="UTF-8" />
+<title>test</title>
+</head>
+<body>
+<ol>
+<li about="#cite_note-5" id="cite_note-5">
+<a href="#cite_ref-5" rel="mw:referencedBy"><span class="mw-linkback-text">↑
</span></a><a href="#cite_ref-5" rel="mw:referencedBy"></a>
+<span class="mw-reference-text" data-parsoid="{}"
id="mw-reference-text-cite_note-5"><a
data-parsoid="{"targetOff":4337,"contentOffsets":[4337,4337],"dsr":[4248,4338,89,1]}"
href="http://lhermanto-resepkeluarga.blogspot.com/2008/04/telor-bumbu-bali-bali-seasoning.html"
rel="mw:ExtLink"></a></span>
+</li>
+</ol>
+</body>
+</html>
diff --git a/tests/lineardoc/data/test3-result.xml
b/tests/lineardoc/data/test3-result.xml
new file mode 100644
index 0000000..f0bc5b3
--- /dev/null
+++ b/tests/lineardoc/data/test3-result.xml
@@ -0,0 +1,51 @@
+<html>
+<cxblockspace/>
+<head>
+<meta charset="UTF-8" />
+<style>cxtextblock { border: solid #88f 1px }
+cxtextchunk { border-right: solid #f88 1px }</style>
+<cxtextblock>
+ <cxtextchunk> </cxtextchunk>
+ <cxinlineelement>
+ <meta/>
+ </cxinlineelement>
+ <cxtextchunk> </cxtextchunk>
+</cxtextblock>
+<title>
+<cxtextblock>
+ <cxtextchunk>test</cxtextchunk>
+</cxtextblock>
+</title>
+<cxblockspace/>
+</head>
+<cxblockspace/>
+<body>
+<cxblockspace/>
+<ol>
+<cxblockspace/>
+<li>
+<cxtextblock>
+ <cxtextchunk> </cxtextchunk>
+ <cxtextchunk tags="a:href=#cite_ref-5,rel=mw:referencedBy
span:class=mw-linkback-text">↑ </cxtextchunk>
+ <cxinlineelement>
+ <a>
+ <cxtextblock>
+ </cxtextblock>
+ </a>
+ </cxinlineelement>
+ <cxtextchunk> </cxtextchunk>
+ <cxinlineelement
tags="span:id=mw-reference-text-cite_note-5,class=mw-reference-text,data-parsoid={}">
+ <a>
+ <cxtextblock>
+ </cxtextblock>
+ </a>
+ </cxinlineelement>
+ <cxtextchunk> </cxtextchunk>
+</cxtextblock>
+</li>
+<cxblockspace/>
+</ol>
+<cxblockspace/>
+</body>
+<cxblockspace/>
+</html>
diff --git a/tests/lineardoc/data/test3.xhtml b/tests/lineardoc/data/test3.xhtml
new file mode 100644
index 0000000..03339e0
--- /dev/null
+++ b/tests/lineardoc/data/test3.xhtml
@@ -0,0 +1,14 @@
+<html>
+<head>
+<meta charset="UTF-8" />
+<title>test</title>
+</head>
+<body>
+<ol>
+<li about="#cite_note-5" id="cite_note-5">
+<a href="#cite_ref-5" rel="mw:referencedBy"><span class="mw-linkback-text">↑
</span></a>
+<span id="mw-reference-text-cite_note-5" class="mw-reference-text"
data-parsoid="{}"><a rel="mw:ExtLink"
href="http://lhermanto-resepkeluarga.blogspot.com/2008/04/telor-bumbu-bali-bali-seasoning.html"
data-parsoid="{"targetOff":4337,"contentOffsets":[4337,4337],"dsr":[4248,4338,89,1]}"></a></span>
+</li>
+</ol>
+</body>
+</html>
--
To view, visit https://gerrit.wikimedia.org/r/222263
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4cca925cb35a00fa27fd31380fae90e1c4c2767f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits