Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/Linkifier.js

Issue 2568983003: Add ability to linkify substituted string
Patch Set: Comments addressed Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 * @return {?UI.Icon} 593 * @return {?UI.Icon}
594 */ 594 */
595 linkIcon(uiSourceCode) {} 595 linkIcon(uiSourceCode) {}
596 }; 596 };
597 597
598 Components.LinkDecorator.Events = { 598 Components.LinkDecorator.Events = {
599 LinkIconChanged: Symbol('LinkIconChanged') 599 LinkIconChanged: Symbol('LinkIconChanged')
600 }; 600 };
601 601
602 /** 602 /**
603 * @param {string} url
604 * @param {string} text
605 * @param {function(string,string,number=,number=):!Node} linkifier
606 * @return {!Node}
607 */
608 Components.Linkifier.createLinkNodeWithCustomLinkifier = function(url, text, lin kifier) {
pfeldman 2017/01/27 19:10:07 It looks like this method is doing nothing. Linkif
karabur 2017/01/27 21:21:04 It does not, this method called with three differe
609 var realURL = (url.startsWith('www.') ? 'http://' + url : url);
610 var splitResult = Common.ParsedURL.splitLineAndColumn(realURL);
611 var linkNode;
612 if (splitResult)
613 linkNode = linkifier(text, splitResult.url, splitResult.lineNumber, splitRes ult.columnNumber);
614 else
615 linkNode = linkifier(text, splitResult.url);
616
617 return linkNode;
618 };
619
620 /**
621 * @param {string} url
622 * @param {string} text
623 * @return {!Node}
624 */
625 Components.Linkifier.createLinkNode = function(url, text) {
pfeldman 2017/01/27 19:10:07 This method also does not do much.
626 /**
627 * @param {string} title
628 * @param {string} url
629 * @param {number=} lineNumber
630 * @param {number=} columnNumber
631 * @return {!Node}
632 */
633 function linkifier(title, url, lineNumber, columnNumber) {
634 return Components.Linkifier.linkifyURL(url, title, undefined, lineNumber, co lumnNumber);
635 }
636
637 return Components.Linkifier.createLinkNodeWithCustomLinkifier(url, text, linki fier);
638 };
639
640 /**
641 * @return {!RegExp}
642 */
643 Components.Linkifier.getLinkRegExp = function() {
pfeldman 2017/01/27 19:10:07 Does this need to be public? Start method with _ i
644 var linkStringRegEx =
645 /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-_+*'=\|\/\\(){}[\]^% @&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/;
646 var pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/;
647
648 return new RegExp(linkStringRegEx.source + '|' + pathLineRegex, 'g');
649 };
650
651 /**
652 * @param {string} string
653 * @return {!Array.<!Common.SourceRange>}
654 */
655 Components.Linkifier.getLinkRanges = function(string) {
pfeldman 2017/01/27 19:10:07 Do we need this public?
656 var regExp = Components.Linkifier.getLinkRegExp();
657 var match = regExp.exec(string);
658 var ranges = [];
659 while (match) {
660 ranges.push(new Common.SourceRange(match.index, match[0].length));
661 match = regExp.exec(string);
662 }
663 return ranges;
664 };
665
666 /**
603 * @param {string} string 667 * @param {string} string
604 * @param {function(string,string,number=,number=):!Node} linkifier 668 * @param {function(string,string,number=,number=):!Node} linkifier
605 * @return {!DocumentFragment} 669 * @return {!DocumentFragment}
606 */ 670 */
607 Components.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifi er) { 671 Components.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifi er) {
608 var container = createDocumentFragment(); 672 var container = createDocumentFragment();
609 var linkStringRegEx =
610 /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-_+*'=\|\/\\(){}[\]^% @&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/;
611 var pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/;
612 673
613 while (string && string.length < Components.Linkifier.MaxLengthToIgnoreLinkifi er) { 674 while (string && string.length < Components.Linkifier.MaxLengthToIgnoreLinkifi er) {
614 var linkString = linkStringRegEx.exec(string) || pathLineRegex.exec(string); 675 var match = Components.Linkifier.getLinkRegExp().exec(string);
615 if (!linkString) 676
677 if (!match)
616 break; 678 break;
617 679
618 linkString = linkString[0]; 680 var linkIndex = match.index;
619 var linkIndex = string.indexOf(linkString); 681 var linkString = match[0];
620 var nonLink = string.substring(0, linkIndex); 682 var nonLink = string.substring(0, linkIndex);
621 container.appendChild(createTextNode(nonLink)); 683 container.appendChild(createTextNode(nonLink));
622 684
623 var title = linkString; 685 var linkNode = Components.Linkifier.createLinkNodeWithCustomLinkifier(linkSt ring, linkString, linkifier);
624 var realURL = (linkString.startsWith('www.') ? 'http://' + linkString : link String);
625 var splitResult = Common.ParsedURL.splitLineAndColumn(realURL);
626 var linkNode;
627 if (splitResult)
628 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber, split Result.columnNumber);
629 else
630 linkNode = linkifier(title, realURL);
631 686
632 container.appendChild(linkNode); 687 container.appendChild(linkNode);
633 string = string.substring(linkIndex + linkString.length, string.length); 688 string = string.substring(linkIndex + linkString.length, string.length);
634 } 689 }
635 690
636 if (string) 691 if (string)
637 container.appendChild(createTextNode(string)); 692 container.appendChild(createTextNode(string));
638 693
639 return container; 694 return container;
640 }; 695 };
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 contextMenu.appendSeparator(); 835 contextMenu.appendSeparator();
781 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); 836 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false));
782 837
783 if (contentProvider instanceof Workspace.UISourceCode) { 838 if (contentProvider instanceof Workspace.UISourceCode) {
784 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); 839 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider );
785 if (!uiSourceCode.project().canSetFileContent()) 840 if (!uiSourceCode.project().canSetFileContent())
786 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); 841 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true));
787 } 842 }
788 } 843 }
789 }; 844 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698