mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-06 11:09:29 +00:00
Replaced parsedown with the newer league/commonmark library
This commit is contained in:
parent
631db7df31
commit
be60c4363c
5 changed files with 514 additions and 63 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue