@@ -25,7 +25,8 @@ class renderer_plugin_edittable_inverse extends Doku_Renderer {
2525 private $ _table = array ();
2626 private $ _liststack = array ();
2727 private $ quotelvl = 0 ;
28- private $ _extlinkparser = null ;
28+ private $ extlinkparser = null ;
29+ protected $ extlinkPatterns = [];
2930
3031 function getFormat () {
3132 return 'wiki ' ;
@@ -250,7 +251,7 @@ function unformatted($text) {
250251 $ this ->not_block ();
251252 if (strpos ($ text , '%% ' ) !== false ) {
252253 $ this ->doc .= "<nowiki> $ text</nowiki> " ;
253- } elseif ($ text{ 0 } == "\n") {
254+ } elseif ($ text[ 0 ] == "\n" ) {
254255 $ this ->doc .= "<nowiki> $ text</nowiki> " ;
255256 } else {
256257 $ this ->doc .= "%% $ text%% " ;
@@ -322,7 +323,7 @@ function _highlight($type, $text, $language = null, $filename = null) {
322323 }
323324 $ this ->doc .= "> " ;
324325 $ this ->doc .= $ text ;
325- if ($ text{ 0 } == "\n") $ this ->doc .= " \n";
326+ if ($ text[ 0 ] == "\n" ) $ this ->doc .= "\n" ;
326327 $ this ->doc .= "</ $ type> " ;
327328 }
328329
@@ -417,14 +418,34 @@ function externallink($url, $name = null) {
417418 * against the URL surrounded by spaces.
418419 */
419420 if ($ name === null ) {
420- // get the patterns from the parser
421- if (is_null ($ this ->_extlinkparser )) {
422- $ this ->_extlinkparser = new Doku_Parser_Mode_externallink ();
423- $ this ->_extlinkparser ->preConnect ();
421+ // get the patterns from the parser if available, otherwise use a duplicate
422+ if (is_null ($ this ->extlinkparser )) {
423+ if (
424+ class_exists ('\dokuwiki\Parsing\ParserMode\Externallink ' ) &&
425+ method_exists ('\dokuwiki\Parsing\ParserMode\Externallink ' , 'getPatterns ' )
426+ ) {
427+ $ this ->extlinkparser = new \dokuwiki \Parsing \ParserMode \Externallink ();
428+ $ this ->extlinkparser ->preConnect ();
429+ $ this ->extlinkPatterns = $ this ->extlinkparser ->getPatterns ();
430+ } else {
431+ $ ltrs = '\w ' ;
432+ $ gunk = '/\#~:.?+=&%@!\-\[\] ' ;
433+ $ punc = '.:?\-;, ' ;
434+ $ host = $ ltrs . $ punc ;
435+ $ any = $ ltrs . $ gunk . $ punc ;
436+
437+ $ schemes = getSchemes ();
438+ foreach ($ schemes as $ scheme ) {
439+ $ this ->extlinkPatterns [] = '\b(?i) ' .$ scheme .'(?-i)://[ ' .$ any .']+?(?=[ ' .$ punc .']*[^ ' .$ any .']) ' ;
440+ }
441+
442+ $ this ->extlinkPatterns [] = '(?<=\s)(?i)www?(?-i)\.[ ' .$ host .']+?\.[ ' .$ host .']+?[ ' .$ any .']+?(?=[ ' .$ punc .']*[^ ' .$ any .']) ' ;
443+ $ this ->extlinkPatterns [] = '(?<=\s)(?i)ftp?(?-i)\.[ ' .$ host .']+?\.[ ' .$ host .']+?[ ' .$ any .']+?(?=[ ' .$ punc .']*[^ ' .$ any .']) ' ;
444+ }
424445 }
425446
426447 // check if URL matches pattern
427- foreach ($ this ->_extlinkparser -> patterns as $ pattern ) {
448+ foreach ($ this ->extlinkPatterns as $ pattern ) {
428449 if (preg_match ("' $ pattern' " , " $ url " )) {
429450 $ this ->doc .= $ url ; // gotcha!
430451 return ;
0 commit comments