Skip to content

Commit

Permalink
Added a switch to enable autolinking of links.
Browse files Browse the repository at this point in the history
As discussed in michelf#326. It's not pretty but it seems to work.
  • Loading branch information
appel committed Oct 25, 2022
1 parent eb176f1 commit bb1cf84
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Michelf/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]>
Expand Down

0 comments on commit bb1cf84

Please sign in to comment.