Replaced parsedown with the newer league/commonmark library
Some checks are pending
Build assets artifact / Build assets artifact (push) Waiting to run
Docker Image Build / docker (push) Waiting to run
Docker Image Build (FrankenPHP) / docker (push) Waiting to run
Static analysis / Static analysis (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, sqlite) (push) Waiting to run

This commit is contained in:
Jan Böhmer 2025-08-14 22:56:20 +02:00
parent 631db7df31
commit be60c4363c
5 changed files with 514 additions and 63 deletions

View file

@ -46,6 +46,10 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part;
use App\Services\Formatters\SIFormatter;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
use League\CommonMark\GithubFlavoredMarkdownConverter;
use League\CommonMark\MarkdownConverter;
use Parsedown;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -54,8 +58,15 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/
final class PartProvider implements PlaceholderProviderInterface
{
private readonly MarkdownConverter $blockConverter;
private readonly MarkdownConverter $inlineConverter;
public function __construct(private readonly SIFormatter $siFormatter, private readonly TranslatorInterface $translator)
{
$this->blockConverter = new GithubFlavoredMarkdownConverter();
$environment = new Environment();
$environment->addExtension(new InlinesOnlyExtension());
$this->inlineConverter = new MarkdownConverter($environment);
}
public function replace(string $placeholder, object $part, array $options = []): ?string
@ -112,22 +123,20 @@ final class PartProvider implements PlaceholderProviderInterface
return $this->translator->trans($part->getManufacturingStatus()->toTranslationKey());
}
$parsedown = new Parsedown();
if ('[[DESCRIPTION]]' === $placeholder) {
return $parsedown->line($part->getDescription());
return $this->inlineConverter->convert($part->getDescription())->getContent();
}
if ('[[DESCRIPTION_T]]' === $placeholder) {
return strip_tags((string) $parsedown->line($part->getDescription()));
return strip_tags($this->inlineConverter->convert($part->getDescription())->getContent());
}
if ('[[COMMENT]]' === $placeholder) {
return $parsedown->line($part->getComment());
return $this->blockConverter->convert($part->getComment())->getContent();
}
if ('[[COMMENT_T]]' === $placeholder) {
return strip_tags((string) $parsedown->line($part->getComment()));
return strip_tags($this->blockConverter->convert($part->getComment())->getContent());
}
return null;