Skip to content

Commit 4d690c7

Browse files
abdounikarimjaviereguiluz
authored andcommitted
Update markdown
1 parent 0583b4d commit 4d690c7

File tree

10 files changed

+169
-79
lines changed

10 files changed

+169
-79
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
"symfony/validator": "5.0.*",
3636
"symfony/webpack-encore-bundle": "^1.4",
3737
"symfony/yaml": "5.0.*",
38-
"tgalopin/html-sanitizer-bundle": "^1.1",
38+
"tgalopin/html-sanitizer-bundle": "^1.2",
3939
"twig/intl-extra": "^3.0",
40+
"twig/markdown-extra": "^3.0",
4041
"twig/twig": "^3.0"
4142
},
4243
"require-dev": {

composer.lock

Lines changed: 145 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bundles.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
1414
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
1515
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
16-
HtmlSanitizer\Bundle\HtmlSanitizerBundle::class => ['all' => true],
1716
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
17+
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
18+
HtmlSanitizer\Bundle\HtmlSanitizerBundle::class => ['all' => true],
1819
];

config/packages/html_sanitizer.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ html_sanitizer:
1010
- 'table'
1111
- 'image'
1212
- 'code'
13+
# - 'iframe'
14+
# - 'extra'
1315

1416
# Read https://github.com/tgalopin/html-sanitizer/blob/master/docs/3-configuration-reference.md
1517
# to discover all the available options for each extension.

config/services.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,3 @@ services:
3232
# 'arguments' key and define the arguments just below the service class
3333
App\EventSubscriber\CommentNotificationSubscriber:
3434
$sender: '%app.notifications.email_sender%'
35-
36-
# needed to activate the filters provided by Twig Intl Extension
37-
Twig\Extra\Intl\IntlExtension: null

src/Twig/AppExtension.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@
1111

1212
namespace App\Twig;
1313

14-
use App\Utils\Markdown;
1514
use Symfony\Component\Intl\Locales;
1615
use Twig\Extension\AbstractExtension;
1716
use Twig\TwigFilter;
1817
use Twig\TwigFunction;
1918

2019
/**
21-
* This Twig extension adds a new 'md2html' filter to easily transform Markdown
22-
* contents into HTML contents inside Twig templates.
23-
*
2420
* See https://symfony.com/doc/current/templating/twig_extension.html
2521
*
2622
* @author Ryan Weaver <[email protected]>
@@ -29,29 +25,16 @@
2925
*/
3026
class AppExtension extends AbstractExtension
3127
{
32-
private $parser;
3328
private $localeCodes;
3429
private $locales;
3530

36-
public function __construct(Markdown $parser, string $locales)
31+
public function __construct(string $locales)
3732
{
38-
$this->parser = $parser;
39-
4033
$localeCodes = explode('|', $locales);
4134
sort($localeCodes);
4235
$this->localeCodes = $localeCodes;
4336
}
4437

45-
/**
46-
* {@inheritdoc}
47-
*/
48-
public function getFilters(): array
49-
{
50-
return [
51-
new TwigFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
52-
];
53-
}
54-
5538
/**
5639
* {@inheritdoc}
5740
*/
@@ -62,14 +45,6 @@ public function getFunctions(): array
6245
];
6346
}
6447

65-
/**
66-
* Transforms the given Markdown content into HTML content.
67-
*/
68-
public function markdownToHtml(string $content): string
69-
{
70-
return $this->parser->toHtml($content);
71-
}
72-
7348
/**
7449
* Takes the list of codes of the locales (languages) enabled in the
7550
* application and returns an array with the name of each locale written

src/Utils/Markdown.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

symfony.lock

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@
473473
"templates/base.html.twig"
474474
]
475475
},
476+
"symfony/twig-pack": {
477+
"version": "v1.0.0"
478+
},
476479
"symfony/validator": {
477480
"version": "4.3",
478481
"recipe": {
@@ -524,7 +527,7 @@
524527
"version": "v4.3.3"
525528
},
526529
"tgalopin/html-sanitizer": {
527-
"version": "1.3.0"
530+
"version": "1.4.0"
528531
},
529532
"tgalopin/html-sanitizer-bundle": {
530533
"version": "1.0",
@@ -533,11 +536,20 @@
533536
"branch": "master",
534537
"version": "1.0",
535538
"ref": "26a72f38eede2c53b5d3ccbed5c150e10a93268d"
536-
}
539+
},
540+
"files": [
541+
"config/packages/html_sanitizer.yaml"
542+
]
543+
},
544+
"twig/extra-bundle": {
545+
"version": "v3.0.3"
537546
},
538547
"twig/intl-extra": {
539548
"version": "v3.0.0"
540549
},
550+
"twig/markdown-extra": {
551+
"version": "v3.0.3"
552+
},
541553
"twig/twig": {
542554
"version": "v2.12.2"
543555
},

templates/admin/blog/show.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<p class="m-b-0"><strong>{{ 'label.summary'|trans }}</strong>: {{ post.summary }}</p>
1515
</div>
1616

17-
{{ post.content|md2html }}
17+
{{ post.content|markdown_to_html|sanitize_html }}
1818

1919
{{ include('blog/_post_tags.html.twig') }}
2020
{% endblock %}

templates/blog/post_show.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<span class="metadata"><i class="fa fa-user"></i> {{ post.author.fullName }}</span>
1111
</p>
1212

13-
{{ post.content|md2html }}
13+
{{ post.content|markdown_to_html|sanitize_html }}
1414

1515
{{ include('blog/_post_tags.html.twig') }}
1616

@@ -48,7 +48,7 @@
4848
<strong>{{ comment.publishedAt|format_datetime('medium', 'short', '', 'UTC') }}</strong>
4949
</h4>
5050
<div class="col-sm-9">
51-
{{ comment.content|md2html }}
51+
{{ comment.content|markdown_to_html|sanitize_html }}
5252
</div>
5353
</div>
5454
{% else %}

0 commit comments

Comments
 (0)