Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/231580
Change subject: Don't include trailing punctuation in autolinked typed text
......................................................................
Don't include trailing punctuation in autolinked typed text
Match the PHP parser rules for stripping trailing punctuation.
Ensure that we still have at least one valid post-protocol character
after stripping stuff from the end.
Change-Id: If21fb4aac13fe3ca9a0253b272a848894f325cf3
---
M src/ui/actions/ve.ui.LinkAction.js
1 file changed, 19 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/80/231580/1
diff --git a/src/ui/actions/ve.ui.LinkAction.js
b/src/ui/actions/ve.ui.LinkAction.js
index 4e118a2..0918932 100644
--- a/src/ui/actions/ve.ui.LinkAction.js
+++ b/src/ui/actions/ve.ui.LinkAction.js
@@ -50,7 +50,7 @@
* @return {boolean} Action was executed
*/
ve.ui.LinkAction.prototype.autolinkUrl = function () {
- var range, rangeEnd, linktext, i,
+ var range, rangeEnd, linktext, punct, i,
surfaceModel = this.surface.getModel(),
documentModel = surfaceModel.getDocument(),
selection = surfaceModel.getSelection();
@@ -66,8 +66,24 @@
range = selection.getRange();
rangeEnd = range.end;
- // Shrink range to eliminate trailing whitespace.
- linktext = documentModel.data.getText( true, range ).replace( /\s+$/,
'' );
+ linktext = documentModel.data.getText( true, range );
+
+ // Eliminate trailing whitespace.
+ linktext = linktext.replace( /\s+$/, '' );
+
+ // Eliminate trailing punctuation, like the PHP parser does:
+ // include ')' in punctuation set only if linktext doesn't have '('
+ punct = /\(/.test(linktext) ? /[,;.:!?]+$/ : /[,;.:!?)]+$/;
+ linktext = linktext.replace( punct, '' );
+
+ // Make sure we still have a real URL after trail removal, and not
+ // a bare protocol (or no protocol at all, if we stripped the last
colon)
+ if ( !ve.ui.LinkAction.static.autolinkRegExp.test( linktext + ' ' ) ) {
+ // Don't autolink this.
+ return false;
+ }
+
+ // Shrink range to match new linktext.
range = range.truncate( linktext.length );
// Check that none of the range has an existing link annotation.
--
To view, visit https://gerrit.wikimedia.org/r/231580
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If21fb4aac13fe3ca9a0253b272a848894f325cf3
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits