Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsedown Extra support #3843

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions extra/markdown-extra/DefaultMarkdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use League\CommonMark\CommonMarkConverter;
use Michelf\MarkdownExtra;
use Parsedown;

class DefaultMarkdown implements MarkdownInterface
{
Expand All @@ -25,7 +24,9 @@ public function __construct()
$this->converter = new LeagueMarkdown();
} elseif (class_exists(MarkdownExtra::class)) {
$this->converter = new MichelfMarkdown();
} elseif (class_exists(Parsedown::class)) {
} elseif (class_exists(\ParsedownExtra::class)) {
$this->converter = new ErusevMarkdownExtra();
} elseif (class_exists(\Parsedown::class)) {
$this->converter = new ErusevMarkdown();
} else {
throw new \LogicException('You cannot use the "markdown_to_html" filter as no Markdown library is available; try running "composer require league/commonmark".');
Expand Down
27 changes: 27 additions & 0 deletions extra/markdown-extra/ErusevMarkdownExtra.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Twig\Extra\Markdown;

class ErusevMarkdownExtra implements MarkdownInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why creating a new ErusevMarkdownExtra ? The existing ErusevMarkdown class supports ParsedownExtra already.

{
private $converter;

public function __construct(\ParsedownExtra $converter = null)
{
$this->converter = $converter ?: new \ParsedownExtra();
}

public function convert(string $body): string
{
return $this->converter->text($body);
}
}
5 changes: 3 additions & 2 deletions extra/markdown-extra/Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Twig\Environment;
use Twig\Extra\Markdown\DefaultMarkdown;
use Twig\Extra\Markdown\ErusevMarkdown;
use Twig\Extra\Markdown\ErusevMarkdownExtra;
use Twig\Extra\Markdown\LeagueMarkdown;
use Twig\Extra\Markdown\MarkdownExtension;
use Twig\Extra\Markdown\MarkdownRuntime;
Expand All @@ -27,9 +28,9 @@ class FunctionalTest extends TestCase
/**
* @dataProvider getMarkdownTests
*/
public function testMarkdown(string $template, string $expected): void
public function testMarkdown(string $template, string $expected)
{
foreach ([LeagueMarkdown::class, ErusevMarkdown::class, /*MichelfMarkdown::class,*/ DefaultMarkdown::class] as $class) {
foreach ([LeagueMarkdown::class, ErusevMarkdown::class, ErusevMarkdownExtra::class, /* MichelfMarkdown::class, */ DefaultMarkdown::class] as $class) {
$twig = new Environment(new ArrayLoader([
'index' => $template,
'html' => <<<EOF
Expand Down
1 change: 1 addition & 0 deletions extra/markdown-extra/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"require-dev": {
"symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0",
"erusev/parsedown": "^1.7",
"erusev/parsedown-extra": "^0.8.1",
"league/commonmark": "^1.0|^2.0",
"league/html-to-markdown": "^4.8|^5.0",
"michelf/php-markdown": "^1.8|^2.0"
Expand Down