Skip to content

Commit 4ec68fd

Browse files
author
roadiz-ci
committed
chore: bumped
1 parent beeff12 commit 4ec68fd

9 files changed

Lines changed: 80 additions & 165 deletions

File tree

.github/workflows/run-test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Static analysis and code style
1+
name: Unit tests, static analysis and code style
22

33
on:
44
push:
@@ -15,11 +15,11 @@ on:
1515
- ready_for_review
1616

1717
jobs:
18-
static-analysis-tests:
18+
run-tests:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
php-version: ['8.3', '8.4', '8.5']
22+
php-version: ['8.1', '8.2', '8.3']
2323
steps:
2424
- uses: shivammathur/setup-php@v2
2525
with:
@@ -35,5 +35,7 @@ jobs:
3535
${{ runner.os }}-php-${{ matrix.php-version }}-
3636
- name: Install Dependencies
3737
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
38+
- name: Run PHP Code Sniffer
39+
run: vendor/bin/phpcs --extensions=php --warning-severity=0 --standard=PSR12 -p ./src
3840
- name: Run PHPStan
3941
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon

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 © 2025 Ambroise Maupate
3+
Copyright © 2024 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

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test:
2+
vendor/bin/phpcs --report=full --report-file=./report.txt -p ./src
3+
vendor/bin/phpstan analyse -c phpstan.neon

composer.json

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
"description": "Markdown services and Twig extension for Roadiz",
44
"type": "library",
55
"require": {
6-
"php": ">=8.3",
7-
"doctrine/collections": ">=1.6",
6+
"php": ">=8.1",
87
"league/commonmark": "^2.2.0",
9-
"symfony/stopwatch": "7.4.*",
10-
"twig/twig": "^3.21"
8+
"twig/twig": "^3.1",
9+
"doctrine/collections": ">=1.6",
10+
"symfony/stopwatch": "6.4.*"
1111
},
1212
"require-dev": {
13-
"phpstan/phpstan": "^2.1.36",
14-
"phpstan/phpdoc-parser": "<2",
15-
"phpunit/phpunit": "^9.6"
13+
"squizlabs/php_codesniffer": "^3.5",
14+
"phpstan/phpstan": "^1.5.3"
1615
},
1716
"license": "MIT",
1817
"authors": [
@@ -28,15 +27,10 @@
2827
"RZ\\Roadiz\\Markdown\\": "src/"
2928
}
3029
},
31-
"autoload-dev": {
32-
"psr-4": {
33-
"RZ\\Roadiz\\Markdown\\Tests\\": "tests/"
34-
}
35-
},
3630
"extra": {
3731
"branch-alias": {
38-
"dev-master": "2.7.x-dev",
39-
"dev-develop": "2.8.x-dev"
32+
"dev-master": "2.3.x-dev",
33+
"dev-develop": "2.4.x-dev"
4034
}
4135
}
4236
}

phpcs.xml.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
4+
5+
<arg name="basepath" value="."/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
<arg name="extensions" value="php"/>
9+
10+
<rule ref="PSR12">
11+
<exclude name="Generic.Files.LineLength"/>
12+
</rule>
13+
<file>./src</file>
14+
</ruleset>

src/CommonMark.php

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,46 @@
77
use League\CommonMark\MarkdownConverter;
88
use Symfony\Component\Stopwatch\Stopwatch;
99

10-
final readonly class CommonMark implements MarkdownInterface
10+
final class CommonMark implements MarkdownInterface
1111
{
1212
public function __construct(
13-
private MarkdownConverter $textConverter,
14-
private MarkdownConverter $textExtraConverter,
15-
private MarkdownConverter $lineConverter,
16-
private MarkdownConverter $textHtmlConverter,
17-
private MarkdownConverter $textExtraHtmlConverter,
18-
private ?Stopwatch $stopwatch = null,
13+
private readonly MarkdownConverter $textConverter,
14+
private readonly MarkdownConverter $textExtraConverter,
15+
private readonly MarkdownConverter $lineConverter,
16+
private readonly ?Stopwatch $stopwatch = null
1917
) {
2018
}
2119

22-
#[\Override]
23-
public function text(?string $markdown = null, bool $allowHtml = false): string
20+
public function text(string $markdown = null): string
2421
{
2522
if (null === $markdown) {
2623
return '';
2724
}
28-
$this->stopwatch?->start(CommonMark::class.'::text');
29-
$converter = $allowHtml ? $this->textHtmlConverter : $this->textConverter;
30-
$html = $converter->convert($markdown)->getContent();
31-
$this->stopwatch?->stop(CommonMark::class.'::text');
32-
25+
$this->stopwatch?->start(CommonMark::class . '::text');
26+
$html = $this->textConverter->convert($markdown)->getContent();
27+
$this->stopwatch?->stop(CommonMark::class . '::text');
3328
return $html;
3429
}
3530

36-
#[\Override]
37-
public function textExtra(?string $markdown = null, bool $allowHtml = false): string
31+
public function textExtra(string $markdown = null): string
3832
{
3933
if (null === $markdown) {
4034
return '';
4135
}
42-
$this->stopwatch?->start(CommonMark::class.'::textExtra');
43-
$converter = $allowHtml ? $this->textExtraHtmlConverter : $this->textExtraConverter;
44-
$html = $converter->convert($markdown)->getContent();
45-
$this->stopwatch?->stop(CommonMark::class.'::textExtra');
46-
36+
$this->stopwatch?->start(CommonMark::class . '::textExtra');
37+
$html = $this->textExtraConverter->convert($markdown)->getContent();
38+
$this->stopwatch?->stop(CommonMark::class . '::textExtra');
4739
return $html;
4840
}
4941

50-
#[\Override]
51-
public function line(?string $markdown = null): string
42+
public function line(string $markdown = null): string
5243
{
5344
if (null === $markdown) {
5445
return '';
5546
}
56-
$this->stopwatch?->start(CommonMark::class.'::line');
47+
$this->stopwatch?->start(CommonMark::class . '::line');
5748
$html = $this->lineConverter->convert($markdown)->getContent();
58-
$this->stopwatch?->stop(CommonMark::class.'::line');
59-
49+
$this->stopwatch?->stop(CommonMark::class . '::line');
6050
return $html;
6151
}
62-
63-
#[\Override]
64-
public function strip(?string $markdown = null): ?string
65-
{
66-
if (!is_string($markdown)) {
67-
return null;
68-
}
69-
/*
70-
* Strip Markdown syntax
71-
*/
72-
$markdown = $this->textExtra($markdown);
73-
// replace BR with space to avoid merged words.
74-
$markdown = str_replace(['<br>', '<br />', '<br/>'], ' ', $markdown);
75-
$markdown = strip_tags($markdown);
76-
/*
77-
* Remove control characters (including DEL).
78-
*/
79-
$markdown = preg_replace('/[\x00-\x1F\x7F]/', '', $markdown);
80-
81-
return $markdown;
82-
}
8352
}

src/MarkdownInterface.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,27 @@ interface MarkdownInterface
99
/**
1010
* Convert Markdown to HTML using standard Markdown syntax.
1111
*
12-
* @param bool $allowHtml Pass true to allow raw HTML (including script/style tags) through
13-
* unchanged. Defaults to false (raw HTML is stripped).
12+
* @param string|null $markdown
13+
*
14+
* @return string
1415
*/
15-
public function text(?string $markdown = null, bool $allowHtml = false): string;
16+
public function text(string $markdown = null): string;
1617

1718
/**
1819
* Convert Markdown to HTML using standard Markdown Extra syntax.
1920
*
20-
* @param bool $allowHtml Pass true to allow raw HTML (including script/style tags) through
21-
* unchanged. Defaults to false (raw HTML is stripped).
21+
* @param string|null $markdown
22+
*
23+
* @return string
2224
*/
23-
public function textExtra(?string $markdown = null, bool $allowHtml = false): string;
25+
public function textExtra(string $markdown = null): string;
2426

2527
/**
2628
* Convert Markdown to HTML using only inline HTML elements.
29+
*
30+
* @param string|null $markdown
31+
*
32+
* @return string
2733
*/
28-
public function line(?string $markdown = null): string;
29-
30-
/**
31-
* Convert Markdown then strip tags, control characters and replace br with whitespace.
32-
*/
33-
public function strip(?string $markdown = null): ?string;
34+
public function line(string $markdown = null): string;
3435
}

src/Twig/MarkdownExtension.php

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

17-
#[\Override]
1817
public function getFilters(): array
1918
{
2019
return [
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']]),
26-
new TwigFilter('strip_markdown', $this->strip(...)),
27-
new TwigFilter('stripMarkdown', $this->strip(...)),
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']]),
2825
];
2926
}
3027

3128
/**
32-
* @param bool $allowHtml Set to true to allow raw HTML (including script/style tags) through
33-
* unchanged. Defaults to false — raw HTML is stripped.
34-
* Usage: {{ content|markdown(true) }}
29+
* @param string|null $input
30+
*
31+
* @return string
3532
*/
36-
public function markdown(?string $input, bool $allowHtml = false): string
33+
public function markdown(?string $input): string
3734
{
3835
if (null === $input) {
3936
return '';
4037
}
41-
42-
return $this->markdown->text($input, $allowHtml);
38+
return $this->markdown->text($input);
4339
}
4440

41+
/**
42+
* @param string|null $input
43+
*
44+
* @return string
45+
*/
4546
public function inlineMarkdown(?string $input): string
4647
{
4748
if (null === $input) {
4849
return '';
4950
}
50-
5151
return $this->markdown->line($input);
5252
}
5353

5454
/**
55-
* @param bool $allowHtml Set to true to allow raw HTML (including script/style tags) through
56-
* unchanged. Defaults to false — raw HTML is stripped.
57-
* Usage: {{ content|markdownExtra(true) }}
55+
* @param string|null $input
56+
*
57+
* @return string
5858
*/
59-
public function markdownExtra(?string $input, bool $allowHtml = false): string
60-
{
61-
if (null === $input) {
62-
return '';
63-
}
64-
65-
return $this->markdown->textExtra($input, $allowHtml);
66-
}
67-
68-
public function strip(?string $input): string
59+
public function markdownExtra(?string $input): string
6960
{
7061
if (null === $input) {
7162
return '';
7263
}
73-
74-
return $this->markdown->strip($input) ?? '';
64+
return $this->markdown->textExtra($input);
7565
}
7666
}

tests/CommonMarkTest.php

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

0 commit comments

Comments
 (0)