diff --git a/app/Note.php b/app/Note.php index afa66b0e..83acf6dc 100644 --- a/app/Note.php +++ b/app/Note.php @@ -7,11 +7,16 @@ use Twitter; use Normalizer; use GuzzleHttp\Client; use Laravel\Scout\Searchable; +use League\CommonMark\Converter; +use League\CommonMark\DocParser; use Jonnybarnes\IndieWeb\Numbers; +use League\CommonMark\Environment; +use League\CommonMark\HtmlRenderer; use Illuminate\Database\Eloquent\Model; use Jonnybarnes\EmojiA11y\EmojiModifier; use League\CommonMark\CommonMarkConverter; use Illuminate\Database\Eloquent\SoftDeletes; +use Jonnybarnes\CommonmarkLinkify\LinkifyExtension; use Illuminate\Database\Eloquent\ModelNotFoundException; class Note extends Model @@ -128,9 +133,12 @@ class Note extends Model */ public function getNoteAttribute($value) { - $markdown = new CommonMarkConverter(); + $environment = Environment::createCommonMarkEnvironment(); + $environment->addExtension(new LinkifyExtension()); + $converter = new Converter(new DocParser($environment), new HtmlRenderer($environment)); $emoji = new EmojiModifier(); - $html = $markdown->convertToHtml($value); + + $html = $converter->convertToHtml($value); $hcards = $this->makeHCards($html); $hashtags = $this->autoLinkHashtag($hcards); $modified = $emoji->makeEmojiAccessible($hashtags); diff --git a/composer.json b/composer.json index 2cb222d3..50901ced 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "ezyang/htmlpurifier": "~4.6", "guzzlehttp/guzzle": "~6.0", "indieauth/client": "~0.1", + "jonnybarnes/commonmark-linkify": "^0.1.0", "jonnybarnes/emoji-a11y": "^0.3", "jonnybarnes/indieweb": "dev-master", "jonnybarnes/webmentions-parser": "0.4.*", diff --git a/composer.lock b/composer.lock index 32dca7d4..bd39c97a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "0f8de1d2b229308f3862ff61f5468fcf", + "content-hash": "4d74fa17d49cf82d75452686d13b3610", "packages": [ { "name": "aws/aws-sdk-php", @@ -1453,6 +1453,51 @@ ], "time": "2015-09-27T15:35:21+00:00" }, + { + "name": "jonnybarnes/commonmark-linkify", + "version": "v0.1", + "source": { + "type": "git", + "url": "https://github.com/jonnybarnes/commonmark-linkify.git", + "reference": "e2db28ede8d82fc040131e9137c167805f16a1a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jonnybarnes/commonmark-linkify/zipball/e2db28ede8d82fc040131e9137c167805f16a1a9", + "reference": "e2db28ede8d82fc040131e9137c167805f16a1a9", + "shasum": "" + }, + "require": { + "league/commonmark": "^0.15.4", + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "~6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Jonnybarnes\\CommonmarkLinkify\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "CC0-1.0" + ], + "authors": [ + { + "name": "Jonny Barnes", + "email": "jonny@jonnybarnes.uk" + } + ], + "description": "Turn plaintext urls into clickable links", + "homepage": "https://github.com/jonnybarnes/commonmark-linkify", + "keywords": [ + "commonmark", + "markdown" + ], + "time": "2017-07-07T16:05:01+00:00" + }, { "name": "jonnybarnes/emoji-a11y", "version": "v0.3",