Skip to content

Commit

Permalink
Merge branch release/v2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Dec 6, 2024
1 parent 1931b22 commit b17ae5a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 71 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1', '8.2', '8.3']
php-version: ['8.2', '8.3']
steps:
- uses: shivammathur/setup-php@v2
with:
Expand All @@ -35,7 +35,5 @@ jobs:
${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install Dependencies
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
- name: Run PHP Code Sniffer
run: vendor/bin/phpcs --extensions=php --warning-severity=0 --standard=PSR12 -p ./src
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon
3 changes: 0 additions & 3 deletions Makefile

This file was deleted.

13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
"description": "Markdown services and Twig extension for Roadiz",
"type": "library",
"require": {
"php": ">=8.1",
"league/commonmark": "^2.2.0",
"twig/twig": "^3.1",
"php": ">=8.2",
"doctrine/collections": ">=1.6",
"symfony/stopwatch": "6.4.*"
"league/commonmark": "^2.2.0",
"symfony/stopwatch": "6.4.*",
"twig/twig": "^3.16"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^1.5.3"
},
"license": "MIT",
Expand All @@ -29,8 +28,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
"dev-master": "2.4.x-dev",
"dev-develop": "2.5.x-dev"
}
}
}
14 changes: 0 additions & 14 deletions phpcs.xml.dist

This file was deleted.

31 changes: 17 additions & 14 deletions src/CommonMark.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,49 @@
use League\CommonMark\MarkdownConverter;
use Symfony\Component\Stopwatch\Stopwatch;

final class CommonMark implements MarkdownInterface
final readonly class CommonMark implements MarkdownInterface
{
public function __construct(
private readonly MarkdownConverter $textConverter,
private readonly MarkdownConverter $textExtraConverter,
private readonly MarkdownConverter $lineConverter,
private readonly ?Stopwatch $stopwatch = null
private MarkdownConverter $textConverter,
private MarkdownConverter $textExtraConverter,
private MarkdownConverter $lineConverter,
private ?Stopwatch $stopwatch = null,
) {
}

public function text(string $markdown = null): string
public function text(?string $markdown = null): string
{
if (null === $markdown) {
return '';
}
$this->stopwatch?->start(CommonMark::class . '::text');
$this->stopwatch?->start(CommonMark::class.'::text');
$html = $this->textConverter->convert($markdown)->getContent();
$this->stopwatch?->stop(CommonMark::class . '::text');
$this->stopwatch?->stop(CommonMark::class.'::text');

return $html;
}

public function textExtra(string $markdown = null): string
public function textExtra(?string $markdown = null): string
{
if (null === $markdown) {
return '';
}
$this->stopwatch?->start(CommonMark::class . '::textExtra');
$this->stopwatch?->start(CommonMark::class.'::textExtra');
$html = $this->textExtraConverter->convert($markdown)->getContent();
$this->stopwatch?->stop(CommonMark::class . '::textExtra');
$this->stopwatch?->stop(CommonMark::class.'::textExtra');

return $html;
}

public function line(string $markdown = null): string
public function line(?string $markdown = null): string
{
if (null === $markdown) {
return '';
}
$this->stopwatch?->start(CommonMark::class . '::line');
$this->stopwatch?->start(CommonMark::class.'::line');
$html = $this->lineConverter->convert($markdown)->getContent();
$this->stopwatch?->stop(CommonMark::class . '::line');
$this->stopwatch?->stop(CommonMark::class.'::line');

return $html;
}
}
18 changes: 3 additions & 15 deletions src/MarkdownInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,16 @@ interface MarkdownInterface
{
/**
* Convert Markdown to HTML using standard Markdown syntax.
*
* @param string|null $markdown
*
* @return string
*/
public function text(string $markdown = null): string;
public function text(?string $markdown = null): string;

/**
* Convert Markdown to HTML using standard Markdown Extra syntax.
*
* @param string|null $markdown
*
* @return string
*/
public function textExtra(string $markdown = null): string;
public function textExtra(?string $markdown = null): string;

/**
* Convert Markdown to HTML using only inline HTML elements.
*
* @param string|null $markdown
*
* @return string
*/
public function line(string $markdown = null): string;
public function line(?string $markdown = null): string;
}
18 changes: 3 additions & 15 deletions src/Twig/MarkdownExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,30 @@ public function getFilters(): array
];
}

/**
* @param string|null $input
*
* @return string
*/
public function markdown(?string $input): string
{
if (null === $input) {
return '';
}

return $this->markdown->text($input);
}

/**
* @param string|null $input
*
* @return string
*/
public function inlineMarkdown(?string $input): string
{
if (null === $input) {
return '';
}

return $this->markdown->line($input);
}

/**
* @param string|null $input
*
* @return string
*/
public function markdownExtra(?string $input): string
{
if (null === $input) {
return '';
}

return $this->markdown->textExtra($input);
}
}

0 comments on commit b17ae5a

Please sign in to comment.