Skip to content

Commit

Permalink
Update to CommonMark v2
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Jul 8, 2021
1 parent 85ceb55 commit 25600be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"doctrine/inflector": "^2.0",
"dragonmantank/cron-expression": "^3.1",
"egulias/email-validator": "^3.1",
"league/commonmark": "^1.3",
"league/commonmark": "^2.0",
"league/flysystem": "^2.0",
"monolog/monolog": "^2.0",
"nesbot/carbon": "^2.31",
Expand Down
16 changes: 9 additions & 7 deletions src/Illuminate/Mail/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Environment;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\Table\TableExtension;
use League\CommonMark\MarkdownConverter;
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;

class Markdown
Expand Down Expand Up @@ -104,15 +105,16 @@ public function renderText($view, array $data = [])
*/
public static function parse($text)
{
$environment = Environment::createCommonMarkEnvironment();
$environment = new Environment([
'allow_unsafe_links' => false,
]);

$environment->addExtension(new CommonMarkCoreExtension);
$environment->addExtension(new TableExtension);

$converter = new CommonMarkConverter([
'allow_unsafe_links' => false,
], $environment);
$converter = new MarkdownConverter($environment);

return new HtmlString($converter->convertToHtml($text));
return new HtmlString($converter->convertToHtml($text)->getContent());
}

/**
Expand Down
13 changes: 10 additions & 3 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace Illuminate\Support;

use Illuminate\Support\Traits\Macroable;
use League\CommonMark\GithubFlavoredMarkdownConverter;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
use League\CommonMark\MarkdownConverter;
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;
use Ramsey\Uuid\Generator\CombGenerator;
use Ramsey\Uuid\Uuid;
Expand Down Expand Up @@ -401,9 +404,13 @@ public static function words($value, $words = 100, $end = '...')
*/
public static function markdown($string, array $options = [])
{
$converter = new GithubFlavoredMarkdownConverter($options);
$environment = new Environment($options);
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new GithubFlavoredMarkdownExtension());

return $converter->convertToHtml($string);
$converter = new MarkdownConverter($environment);

return $converter->convertToHtml($string)->getContent();
}

/**
Expand Down

0 comments on commit 25600be

Please sign in to comment.