From c4e67ff342a60ae2e62fd40204f87bb79d6b9226 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 5 Dec 2024 19:36:08 +0100 Subject: [PATCH] Add suffix to heading identifiers of the same name --- .../Feature/MarkdownHeadingRendererTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php b/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php index a2ce05f455e..3ade050fa68 100644 --- a/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php +++ b/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php @@ -240,4 +240,44 @@ public function testCustomPageClassConfiguration() $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); $this->assertStringNotContainsString('heading-permalink', $html); } + + public function testItHandlesMultipleHeadingsWithTheSameName() + { + $markdown = <<<'MARKDOWN' + ## Heading + ## Heading + ## Unique Heading + ## With Children + ### Child Heading + ### Child Heading + ### Unique Child Heading + #### Child Heading + MARKDOWN; + + $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + + $this->assertSame(<<<'HTML' +

Heading#

+

Heading#

+

Unique Heading#

+

With Children#

+

Child Heading#

+

Child Heading#

+

Unique Child Heading#

+

Child Heading#

+ + HTML, $html); + } + + public function testDoesNotChangeAnythingIfMultipleHeadingsWithTheSameNameAreInDifferentPages() + { + $markdown = <<<'MARKDOWN' + ## Heading + MARKDOWN; + + $html1 = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + $html2 = (new MarkdownService($markdown, DocumentationPage::class))->parse(); + + $this->assertSame($html1, $html2); + } }