diff --git a/src/Converter/Parsedown.php b/src/Converter/Parsedown.php index 488cad889..c286bf009 100644 --- a/src/Converter/Parsedown.php +++ b/src/Converter/Parsedown.php @@ -20,7 +20,13 @@ use Cecil\Util; use Highlight\Highlighter; -class Parsedown extends \ParsedownToC +/** + * @property array $InlineTypes + * @property string $inlineMarkerList + * @property array $specialCharacters + * @property array $BlockTypes + */ +class Parsedown extends \ParsedownToc { /** @var Builder */ protected $builder; @@ -59,7 +65,8 @@ public function __construct(Builder $builder, ?array $options = null) // options $options = array_merge(['selectors' => (array) $this->config->get('pages.body.toc')], $options ?? []); - parent::__construct($options); + parent::__construct(); + parent::setOptions($options); } /** @@ -89,7 +96,7 @@ protected function inlineInsert($Excerpt) */ protected function inlineLink($Excerpt) { - $link = parent::inlineLink($Excerpt); + $link = parent::inlineLink($Excerpt); // @phpstan-ignore staticMethod.notFound if (!isset($link)) { return null; @@ -235,7 +242,7 @@ protected function inlineLink($Excerpt) */ protected function inlineImage($Excerpt) { - $InlineImage = parent::inlineImage($Excerpt); + $InlineImage = parent::inlineImage($Excerpt); // @phpstan-ignore staticMethod.notFound if (!isset($InlineImage)) { return null; } @@ -429,7 +436,7 @@ protected function inlineImage($Excerpt) ], ]; $picture['element']['text'][] = $source['element']; - unset($image['element']['attributes']['title']); + unset($image['element']['attributes']['title']); // @phpstan-ignore unset.offset $picture['element']['text'][] = $image['element']; $image = $picture; } catch (\Exception $e) { @@ -648,7 +655,7 @@ private function createFigure(array $inline): array return $inline; } - $titleRawHtml = $this->line($inline['element']['attributes']['title']); + $titleRawHtml = $this->line($inline['element']['attributes']['title']); // @phpstan-ignore method.notFound $inline['element']['attributes']['title'] = strip_tags($titleRawHtml); $figcaption = [ diff --git a/src/Renderer/Extension/Core.php b/src/Renderer/Extension/Core.php index 4f81c04ce..d3eb333df 100644 --- a/src/Renderer/Extension/Core.php +++ b/src/Renderer/Extension/Core.php @@ -679,12 +679,13 @@ public function markdownToHtml(?string $markdown): ?string * * @throws RuntimeException */ - public function markdownToToc(?string $markdown, $format = 'html', $url = ''): ?string + public function markdownToToc(?string $markdown, $format = 'html', ?array $selectors = null, string $url = ''): ?string { $markdown = $markdown ?? ''; + $selectors = $selectors ?? (array) $this->config->get('pages.body.toc'); try { - $parsedown = new Parsedown($this->builder, ['selectors' => ['h2'], 'url' => $url]); + $parsedown = new Parsedown($this->builder, ['selectors' => $selectors, 'url' => $url]); $parsedown->body($markdown); $return = $parsedown->contentsList($format); } catch (\Exception) { diff --git a/tests/fixtures/website/layouts/markdown-filter.html.twig b/tests/fixtures/website/layouts/markdown-filter.html.twig index d4be51cbc..836ab2019 100644 --- a/tests/fixtures/website/layouts/markdown-filter.html.twig +++ b/tests/fixtures/website/layouts/markdown-filter.html.twig @@ -4,6 +4,8 @@ {{ page.content }} +
markdown_to_html
filtertoc
filter