Skip to content

Commit 6e02813

Browse files
authored
Merge pull request #193 from cosmocode/hogfather
Fix external links without a title in Hogfather
2 parents 1917599 + 3a2998a commit 6e02813

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
language: php
22
php:
3+
- "nightly"
4+
- "7.4"
5+
- "7.3"
6+
- "7.2"
37
- "7.1"
48
- "7.0"
59
- "5.6"
610
env:
711
- DOKUWIKI=master
12+
matrix:
13+
allow_failures:
14+
- php: "nightly"
815
before_install:
916
- wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh
1017
- npm install
1118
install: sh travis.sh
1219
script:
13-
- cd _test && phpunit --stderr --group plugin_edittable
20+
- cd _test && ./phpunit.phar --stderr --group plugin_edittable
1421
- cd ../lib/plugins/edittable && grunt
1522
- grunt eslint

renderer/inverse.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)