Skip to content

Commit bb1cf84

Browse files
authored
Added a switch to enable autolinking of links.
As discussed in michelf#326. It's not pretty but it seems to work.
1 parent eb176f1 commit bb1cf84

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Michelf/Markdown.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public static function defaultTransform(string $text): string {
6565
public bool $no_markup = false;
6666
public bool $no_entities = false;
6767

68+
/**
69+
* Change to `true` to enable autolinking without the need for angle brackets
70+
* @var boolean
71+
*/
72+
public bool $autolinks = false;
6873

6974
/**
7075
* Change to `true` to enable line breaks on \n without two trailling spaces
@@ -1606,7 +1611,16 @@ protected function encodeAmpsAndAngles($text) {
16061611
* @return string
16071612
*/
16081613
protected function doAutoLinks($text) {
1609-
$text = preg_replace_callback('{<((https?|ftp|dict|tel):[^\'">\s]+)>}i',
1614+
if ($this->autolinks)
1615+
{
1616+
$regex = '{((https?|ftp|dict|tel):[^\'">\s]+)}i';
1617+
}
1618+
else
1619+
{
1620+
$regex = '{<((https?|ftp|dict|tel):[^\'">\s]+)>}i';
1621+
}
1622+
1623+
$text = preg_replace_callback($regex,
16101624
array($this, '_doAutoLinks_url_callback'), $text);
16111625

16121626
// Email addresses: <[email protected]>

0 commit comments

Comments
 (0)