Skip to content

Commit 3a0dde4

Browse files
author
roadiz-ci
committed
Merge branch hotfix/v2.7.24
1 parent 85bea20 commit 3a0dde4

6 files changed

Lines changed: 47 additions & 23 deletions

File tree

.github/workflows/run-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
php-version: ['8.2', '8.3']
22+
php-version: ['8.3', '8.4']
2323
steps:
2424
- uses: shivammathur/setup-php@v2
2525
with:

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright © 2024 Ambroise Maupate
3+
Copyright © 2025 Ambroise Maupate
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"description": "Markdown services and Twig extension for Roadiz",
44
"type": "library",
55
"require": {
6-
"php": ">=8.2",
6+
"php": ">=8.3",
77
"doctrine/collections": ">=1.6",
88
"league/commonmark": "^2.2.0",
9-
"symfony/stopwatch": "6.4.*",
10-
"twig/twig": "^3.16"
9+
"symfony/stopwatch": "7.4.*",
10+
"twig/twig": "^3.21"
1111
},
1212
"require-dev": {
13-
"phpstan/phpstan": "^1.5.3",
13+
"phpstan/phpstan": "^2.1.36",
1414
"phpstan/phpdoc-parser": "<2"
1515
},
1616
"license": "MIT",
@@ -29,8 +29,8 @@
2929
},
3030
"extra": {
3131
"branch-alias": {
32-
"dev-master": "2.5.x-dev",
33-
"dev-develop": "2.6.x-dev"
32+
"dev-master": "2.7.x-dev",
33+
"dev-develop": "2.8.x-dev"
3434
}
3535
}
3636
}

src/CommonMark.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,41 @@ public function __construct(
1313
private MarkdownConverter $textConverter,
1414
private MarkdownConverter $textExtraConverter,
1515
private MarkdownConverter $lineConverter,
16+
private MarkdownConverter $textHtmlConverter,
17+
private MarkdownConverter $textExtraHtmlConverter,
1618
private ?Stopwatch $stopwatch = null,
1719
) {
1820
}
1921

20-
public function text(?string $markdown = null): string
22+
#[\Override]
23+
public function text(?string $markdown = null, bool $allowHtml = false): string
2124
{
2225
if (null === $markdown) {
2326
return '';
2427
}
2528
$this->stopwatch?->start(CommonMark::class.'::text');
26-
$html = $this->textConverter->convert($markdown)->getContent();
29+
$converter = $allowHtml ? $this->textHtmlConverter : $this->textConverter;
30+
$html = $converter->convert($markdown)->getContent();
2731
$this->stopwatch?->stop(CommonMark::class.'::text');
2832

2933
return $html;
3034
}
3135

32-
public function textExtra(?string $markdown = null): string
36+
#[\Override]
37+
public function textExtra(?string $markdown = null, bool $allowHtml = false): string
3338
{
3439
if (null === $markdown) {
3540
return '';
3641
}
3742
$this->stopwatch?->start(CommonMark::class.'::textExtra');
38-
$html = $this->textExtraConverter->convert($markdown)->getContent();
43+
$converter = $allowHtml ? $this->textExtraHtmlConverter : $this->textExtraConverter;
44+
$html = $converter->convert($markdown)->getContent();
3945
$this->stopwatch?->stop(CommonMark::class.'::textExtra');
4046

4147
return $html;
4248
}
4349

50+
#[\Override]
4451
public function line(?string $markdown = null): string
4552
{
4653
if (null === $markdown) {

src/MarkdownInterface.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ interface MarkdownInterface
88
{
99
/**
1010
* Convert Markdown to HTML using standard Markdown syntax.
11+
*
12+
* @param bool $allowHtml Pass true to allow raw HTML (including script/style tags) through
13+
* unchanged. Defaults to false (raw HTML is stripped).
1114
*/
12-
public function text(?string $markdown = null): string;
15+
public function text(?string $markdown = null, bool $allowHtml = false): string;
1316

1417
/**
1518
* Convert Markdown to HTML using standard Markdown Extra syntax.
19+
*
20+
* @param bool $allowHtml Pass true to allow raw HTML (including script/style tags) through
21+
* unchanged. Defaults to false (raw HTML is stripped).
1622
*/
17-
public function textExtra(?string $markdown = null): string;
23+
public function textExtra(?string $markdown = null, bool $allowHtml = false): string;
1824

1925
/**
2026
* Convert Markdown to HTML using only inline HTML elements.

src/Twig/MarkdownExtension.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,30 @@ public function __construct(private readonly MarkdownInterface $markdown)
1414
{
1515
}
1616

17+
#[\Override]
1718
public function getFilters(): array
1819
{
1920
return [
20-
new TwigFilter('markdown', [$this, 'markdown'], ['is_safe' => ['html']]),
21-
new TwigFilter('inlineMarkdown', [$this, 'inlineMarkdown'], ['is_safe' => ['html']]),
22-
new TwigFilter('inline_markdown', [$this, 'inlineMarkdown'], ['is_safe' => ['html']]),
23-
new TwigFilter('markdownExtra', [$this, 'markdownExtra'], ['is_safe' => ['html']]),
24-
new TwigFilter('markdown_extra', [$this, 'markdownExtra'], ['is_safe' => ['html']]),
21+
new TwigFilter('markdown', $this->markdown(...), ['is_safe' => ['html']]),
22+
new TwigFilter('inlineMarkdown', $this->inlineMarkdown(...), ['is_safe' => ['html']]),
23+
new TwigFilter('inline_markdown', $this->inlineMarkdown(...), ['is_safe' => ['html']]),
24+
new TwigFilter('markdownExtra', $this->markdownExtra(...), ['is_safe' => ['html']]),
25+
new TwigFilter('markdown_extra', $this->markdownExtra(...), ['is_safe' => ['html']]),
2526
];
2627
}
2728

28-
public function markdown(?string $input): string
29+
/**
30+
* @param bool $allowHtml Set to true to allow raw HTML (including script/style tags) through
31+
* unchanged. Defaults to false — raw HTML is stripped.
32+
* Usage: {{ content|markdown(true) }}
33+
*/
34+
public function markdown(?string $input, bool $allowHtml = false): string
2935
{
3036
if (null === $input) {
3137
return '';
3238
}
3339

34-
return $this->markdown->text($input);
40+
return $this->markdown->text($input, $allowHtml);
3541
}
3642

3743
public function inlineMarkdown(?string $input): string
@@ -43,12 +49,17 @@ public function inlineMarkdown(?string $input): string
4349
return $this->markdown->line($input);
4450
}
4551

46-
public function markdownExtra(?string $input): string
52+
/**
53+
* @param bool $allowHtml Set to true to allow raw HTML (including script/style tags) through
54+
* unchanged. Defaults to false — raw HTML is stripped.
55+
* Usage: {{ content|markdownExtra(true) }}
56+
*/
57+
public function markdownExtra(?string $input, bool $allowHtml = false): string
4758
{
4859
if (null === $input) {
4960
return '';
5061
}
5162

52-
return $this->markdown->textExtra($input);
63+
return $this->markdown->textExtra($input, $allowHtml);
5364
}
5465
}

0 commit comments

Comments
 (0)