GWicke has uploaded a new change for review.
https://gerrit.wikimedia.org/r/99587
Change subject: Bug 58054: Implement URL link parenthesis heuristic
......................................................................
Bug 58054: Implement URL link parenthesis heuristic
Change-Id: Ib09009dd5be74f78bdfcf784f734c9e1067667ea
---
M js/lib/pegTokenizer.pegjs.txt
M js/tests/parserTests.txt
2 files changed, 79 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/87/99587/1
diff --git a/js/lib/pegTokenizer.pegjs.txt b/js/lib/pegTokenizer.pegjs.txt
index 759bd82..898d581 100644
--- a/js/lib/pegTokenizer.pegjs.txt
+++ b/js/lib/pegTokenizer.pegjs.txt
@@ -801,7 +801,21 @@
urllink
= target:url {
- return [ new SelfclosingTagTk( 'urllink', [new KV('href', target)], {
tsr: [pos0, pos] } ) ];
+ // Special case handling for trailing parentheses: remove from link if
+ // there is no opening parenthesis in the link
+ var unmatchedParenthesis = '';
+ if (!/[(]/.test(target) && /[)]$/.test(target)) {
+ target = target.substr(0, target.length - 1);
+ unmatchedParenthesis = ')';
+ pos--;
+ }
+
+ var res = [ new SelfclosingTagTk( 'urllink', [new KV('href', target)], {
tsr: [pos0, pos] } ) ];
+ //if (unmatchedParenthesis) {
+ // // convert the parenthesis back to text
+ // res.push(unmatchedParenthesis);
+ //}
+ return res;
}
extlink
diff --git a/js/tests/parserTests.txt b/js/tests/parserTests.txt
index 6a96970..48ecf20 100644
--- a/js/tests/parserTests.txt
+++ b/js/tests/parserTests.txt
@@ -4032,6 +4032,70 @@
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a></p>
!! end
+!! test
+Parenthesis in external links, especially URL links
+!! options
+php
+!! input
+http://example.com)
+
+http://example.com/test)
+
+http://example.com/(test)
+
+http://example.com/((test)
+
+(http://example.com/(test))
+
+(http://example.com/(test)))))
+
+http://example.com/a)b
+
+[http://example.com) foo]
+!! result
+<p><a rel="nofollow" class="external free"
href="http://example.com">http://example.com</a>)
+</p><p><a rel="nofollow" class="external free"
href="http://example.com/test">http://example.com/test</a>)
+</p><p><a rel="nofollow" class="external free"
href="http://example.com/(test)">http://example.com/(test)</a>
+</p><p><a rel="nofollow" class="external free"
href="http://example.com/((test)">http://example.com/((test)</a>
+</p><p>(<a rel="nofollow" class="external free"
href="http://example.com/(test))">http://example.com/(test))</a>
+</p><p>(<a rel="nofollow" class="external free"
href="http://example.com/(test)))))">http://example.com/(test)))))</a>
+</p><p><a rel="nofollow" class="external free"
href="http://example.com/a)b">http://example.com/a)b</a>
+</p><p><a rel="nofollow" class="external text"
href="http://example.com)">foo</a>
+</p>
+!! end
+
+!! test
+Parenthesis in external links, especially URL links (Parsoid)
+!! options
+parsoid
+!! input
+http://example.com)
+
+http://example.com/test)
+
+http://example.com/(test)
+
+http://example.com/((test)
+
+(http://example.com/(test))
+
+(http://example.com/(test)))))
+
+http://example.com/a)b
+
+[http://example.com) foo]
+!! result
+<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a>)</p>
+<p><a rel="mw:ExtLink"
href="http://example.com/test">http://example.com/test</a>)</p>
+<p><a rel="mw:ExtLink"
href="http://example.com/(test)">http://example.com/(test)</a></p>
+<p><a rel="mw:ExtLink"
href="http://example.com/((test)">http://example.com/((test)</a></p>
+<p>(<a rel="mw:ExtLink"
href="http://example.com/(test))">http://example.com/(test))</a></p>
+<p>(<a rel="mw:ExtLink"
href="http://example.com/(test)))))">http://example.com/(test)))))</a></p>
+<p><a rel="mw:ExtLink"
href="http://example.com/a)b">http://example.com/a)b</a></p>
+<p><a rel="mw:ExtLink" href="http://example.com)">foo</a></p>
+!! end
+
+
###
### Quotes
###
--
To view, visit https://gerrit.wikimedia.org/r/99587
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib09009dd5be74f78bdfcf784f734c9e1067667ea
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: GWicke <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits