OLD | NEW |
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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 return uiLocation.linkText(); | 443 return uiLocation.linkText(); |
444 } | 444 } |
445 | 445 |
446 /** | 446 /** |
447 * @param {string} string | 447 * @param {string} string |
448 * @param {function(string,string,number=,number=):!Node} linkifier | 448 * @param {function(string,string,number=,number=):!Node} linkifier |
449 * @return {!DocumentFragment} | 449 * @return {!DocumentFragment} |
450 */ | 450 */ |
451 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki
fier) | 451 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki
fier) |
452 { | 452 { |
453 // Spec: https://url.spec.whatwg.org/#url-code-points | |
454 var container = createDocumentFragment(); | 453 var container = createDocumentFragment(); |
455 var protocol = "(?:[a-zA-Z][a-zA-Z0-9]{2,}://"; | 454 var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-
_+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/; |
456 var userPassLogin = "(?:\\w+(?::\\w+)?@)?"; | |
457 var domainOrIPV4 = "[a-zA-Z0-9](?:[a-zA-Z0-9]*|(?:-|\\.)[a-zA-Z0-9]+)+"; | |
458 var ipv6 = "\\[(?:(?::|\\.)?[a-zA-Z0-9]{0,4}){2,8}\\]"; | |
459 var portPattern = "(?::[0-9]{1,4})"; | |
460 var domainPattern = "(?:" + ipv6 + "|" + domainOrIPV4 + ")" + portPattern +
"?"; | |
461 var encodedURIPattern = "%[0-9]{2}"; | |
462 var mayContainPunctuationIfNoSpaceAfter = "[.,:;](?!\\s|$)"; | |
463 var uriPattern = "(?:(?:\\?|/|#)(?:[\\w" + | |
464 "!$&'()*+\\-/=?#@_~" + | |
465 "\\u{00A0}-\\u{D7FF}" + | |
466 "\\u{E000}-\\u{FDCF}" + | |
467 "\\u{FDF0}-\\u{FFFD}" + | |
468 "\\u{10000}-\\u{1FFFD}" + | |
469 "\\u{20000}-\\u{2FFFD}" + | |
470 "\\u{30000}-\\u{3FFFD}" + | |
471 "\\u{40000}-\\u{4FFFD}" + | |
472 "\\u{50000}-\\u{5FFFD}" + | |
473 "\\u{60000}-\\u{6FFFD}" + | |
474 "\\u{70000}-\\u{7FFFD}" + | |
475 "\\u{80000}-\\u{8FFFD}" + | |
476 "\\u{90000}-\\u{9FFFD}" + | |
477 "\\u{A0000}-\\u{AFFFD}" + | |
478 "\\u{B0000}-\\u{BFFFD}" + | |
479 "\\u{C0000}-\\u{CFFFD}" + | |
480 "\\u{D0000}-\\u{DFFFD}" + | |
481 "\\u{E0000}-\\u{EFFFD}" + | |
482 "\\u{F0000}-\\u{FFFFD}" + | |
483 "\\u{100000}-\\u{10FFFD}" + | |
484 "]*|" + mayContainPunctuationIfNoSpaceAfter + "|" + encodedURIPattern +
")*)?"; | |
485 var beginInPunctuationOrSpace = "([;:.,\\s;]|^)"; | |
486 var endInPunctuationOrSpace = "(?=[;:.,\\s;]|$)"; | |
487 var dataURI = "data:[^,]*,"; | |
488 var protocolPattern = protocol + userPassLogin + domainPattern + "|www\\.(?:
" + domainOrIPV4 + ")" + portPattern + "?)"; | |
489 var doubleQuotes = "\"(?:" + protocolPattern + "|" + dataURI + ")[^\"]*(?=\"
)"; | |
490 var singleQuotes = "'(?:" + protocolPattern + "|" + dataURI + ")[^']*(?=')"; | |
491 var accentQuotes = "`(?:" + protocolPattern + "|" + dataURI + ")[^`]*(?=`)"; | |
492 var parenthesis = "\\((?:" + protocolPattern + "|" + dataURI + ")[^)]*(?=\\)
)"; | |
493 var squareBrackets = "\\[(?:" + protocolPattern + "|" + dataURI + ")[^\\]]*(
?=\\])"; | |
494 var linkStringRegEx = new RegExp("(?:(?:" + doubleQuotes + "|" + singleQuote
s + "|" + accentQuotes + "|" + parenthesis + "|" + squareBrackets + ")|" + begin
InPunctuationOrSpace + protocolPattern + uriPattern + endInPunctuationOrSpace +
")", "u"); | |
495 | 455 |
496 while (string && string.length < WebInspector.Linkifier.MaxLengthToIgnoreLin
kifier) { | 456 while (string && string.length < WebInspector.Linkifier.MaxLengthToIgnoreLin
kifier) { |
497 var match = linkStringRegEx.exec(string); | 457 var linkString = linkStringRegEx.exec(string); |
498 if (!match) | 458 if (!linkString) |
499 break; | 459 break; |
500 var linkString = match[0]; | |
501 var firstChar = linkString[0]; | |
502 if (firstChar === "'" || firstChar === "\"" || firstChar === "`" || firs
tChar === "(" || firstChar === "[") { | |
503 match.index += 1; | |
504 linkString = linkString.substr(1); | |
505 } | |
506 var nonAlphaNumericFirstCharacter = match[1] | |
507 if (nonAlphaNumericFirstCharacter) { | |
508 // Unmatches/removes beginInPunctuationOrSpace from match. | |
509 match.index += nonAlphaNumericFirstCharacter.length; | |
510 linkString = linkString.substr(nonAlphaNumericFirstCharacter.length)
; | |
511 } | |
512 | 460 |
513 | 461 linkString = linkString[0]; |
514 var linkIndex = match.index; | 462 var linkIndex = string.indexOf(linkString); |
515 var nonLink = string.substring(0, linkIndex); | 463 var nonLink = string.substring(0, linkIndex); |
516 container.appendChild(createTextNode(nonLink)); | 464 container.appendChild(createTextNode(nonLink)); |
517 | 465 |
518 var title = linkString; | 466 var title = linkString; |
519 var realURL = (linkString.startsWith("www.") ? "http://" + linkString :
linkString); | 467 var realURL = (linkString.startsWith("www.") ? "http://" + linkString :
linkString); |
520 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(realURL); | 468 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(realURL); |
521 var linkNode; | 469 var linkNode; |
522 if (splitResult) | 470 if (splitResult) |
523 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber,
splitResult.columnNumber); | 471 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber,
splitResult.columnNumber); |
524 else | 472 else |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 /** | 534 /** |
587 * @param {!WebInspector.NetworkRequest} request | 535 * @param {!WebInspector.NetworkRequest} request |
588 * @return {!Element} | 536 * @return {!Element} |
589 */ | 537 */ |
590 WebInspector.linkifyRequestAsNode = function(request) | 538 WebInspector.linkifyRequestAsNode = function(request) |
591 { | 539 { |
592 var anchor = WebInspector.linkifyURLAsNode(request.url); | 540 var anchor = WebInspector.linkifyURLAsNode(request.url); |
593 anchor.requestId = request.requestId; | 541 anchor.requestId = request.requestId; |
594 return anchor; | 542 return anchor; |
595 } | 543 } |
OLD | NEW |