forked from michelf/php-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a switch to enable autolinking of links.
As discussed in michelf#326. It's not pretty but it seems to work.
- Loading branch information
Showing
1 changed file
with
15 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,11 @@ public static function defaultTransform(string $text): string { | |
public bool $no_markup = false; | ||
public bool $no_entities = false; | ||
|
||
/** | ||
* Change to `true` to enable autolinking without the need for angle brackets | ||
* @var boolean | ||
*/ | ||
public bool $autolinks = false; | ||
|
||
/** | ||
* Change to `true` to enable line breaks on \n without two trailling spaces | ||
|
@@ -1606,7 +1611,16 @@ protected function encodeAmpsAndAngles($text) { | |
* @return string | ||
*/ | ||
protected function doAutoLinks($text) { | ||
$text = preg_replace_callback('{<((https?|ftp|dict|tel):[^\'">\s]+)>}i', | ||
if ($this->autolinks) | ||
{ | ||
$regex = '{((https?|ftp|dict|tel):[^\'">\s]+)}i'; | ||
} | ||
else | ||
{ | ||
$regex = '{<((https?|ftp|dict|tel):[^\'">\s]+)>}i'; | ||
} | ||
|
||
$text = preg_replace_callback($regex, | ||
array($this, '_doAutoLinks_url_callback'), $text); | ||
|
||
// Email addresses: <[email protected]> | ||
|