PluginProbe
OPcache Manager / 3.3.0
OPcache Manager v3.3.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.13.0 2.13.1 2.14.0 2.2.0 2.3.0 2.3.1 2.3.2 2.4.0 2.5.0 2.6.0 All 36 releases
opcache-manager / includes / libraries / markdown / inline / UrlLinkTrait.php

UrlLinkTrait.php in OPcache Manager 3.3.0, at includes/libraries/markdown/inline/UrlLinkTrait.php

51 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @copyright Copyright (c) 2014 Carsten Brandt
4 * @license https://github.com/cebe/markdown/blob/master/LICENSE
5 * @link https://github.com/cebe/markdown#readme
6 */
7
8 namespace cebe\markdownparser\inline;
9
10 // work around https://github.com/facebook/hhvm/issues/1120
11 defined('ENT_HTML401') || define('ENT_HTML401', 0);
12
13 /**
14 * Adds auto linking for URLs
15 */
16 trait UrlLinkTrait
17 {
18 /**
19 * Parses urls and adds auto linking feature.
20 * @marker http
21 * @marker ftp
22 */
23 protected function parseUrl($markdown)
24 {
25 $pattern = <<<REGEXP
26 /(?(R) # in case of recursion match parentheses
27 \(((?>[^\s()]+)|(?R))*\)
28 | # else match a link with title
29 ^(https?|ftp):\/\/(([^\s<>()]+)|(?R))+(?<![\.,:;\'"!\?\s])
30 )/x
31 REGEXP;
32
33 if (!in_array('parseLink', $this->context) && preg_match($pattern, $markdown, $matches)) {
34 return [
35 ['autoUrl', $matches[0]],
36 strlen($matches[0])
37 ];
38 }
39 return [['text', substr($markdown, 0, 4)], 4];
40 }
41
42 protected function renderAutoUrl($block)
43 {
44 $href = htmlspecialchars($block[1], ENT_COMPAT | ENT_HTML401, 'UTF-8');
45 $decodedUrl = urldecode($block[1]);
46 $secureUrlText = preg_match('//u', $decodedUrl) ? $decodedUrl : $block[1];
47 $text = htmlspecialchars($secureUrlText, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
48 return "<a href=\"$href\">$text</a>";
49 }
50 }
51