From 7f79bee5fa7fad051e5ab2970c84edf4ccfd4ee2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 4 Dec 2024 09:38:59 +0100 Subject: [PATCH 01/10] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 6efc73d5857..8d927a0193a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -104,6 +104,7 @@ This serves two purposes: - Normalized default Tailwind Typography Prose code block styles to match Torchlight's theme, ensuring consistent styling across Markdown and Torchlight code blocks in https://github.com/hydephp/develop/pull/2036. - Extracted CSS component partials in HydeFront in https://github.com/hydephp/develop/pull/2038 - Replaced HydeFront styles with Tailwind in https://github.com/hydephp/develop/pull/2024 +- The `id` attributes for heading permalinks have been moved from the anchor to the heading element in https://github.com/hydephp/develop/pull/2052 ### Deprecated From 0710e95dd1d79cea105a7c254a770ec0fd3aa9c8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 4 Dec 2024 09:25:08 +0100 Subject: [PATCH 02/10] More semantic Markdown heading permalinks --- .../resources/views/components/markdown-heading.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/resources/views/components/markdown-heading.blade.php b/packages/framework/resources/views/components/markdown-heading.blade.php index a0dec20101f..a41d8dd22bb 100644 --- a/packages/framework/resources/views/components/markdown-heading.blade.php +++ b/packages/framework/resources/views/components/markdown-heading.blade.php @@ -10,9 +10,9 @@ $id = $id ?? \Illuminate\Support\Str::slug($slot); @endphp -<{{ $tag }} {{ $attributes->merge([...$extraAttributes]) }}> +<{{ $tag }} {{ $attributes->merge(['id' => $id, ...$extraAttributes]) }}> {!! $slot !!} @if($addPermalink === true) - + @endif \ No newline at end of file From 8737a5240ce51da23961776356a958e0007fdb37 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 4 Dec 2024 09:27:42 +0100 Subject: [PATCH 03/10] Conditionally add element identifier --- .../resources/views/components/markdown-heading.blade.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/framework/resources/views/components/markdown-heading.blade.php b/packages/framework/resources/views/components/markdown-heading.blade.php index a41d8dd22bb..f4af7c2a80a 100644 --- a/packages/framework/resources/views/components/markdown-heading.blade.php +++ b/packages/framework/resources/views/components/markdown-heading.blade.php @@ -8,9 +8,13 @@ @php $tag = 'h' . $level; $id = $id ?? \Illuminate\Support\Str::slug($slot); + + if ($addPermalink === true) { + $extraAttributes['id'] = $id; + } @endphp -<{{ $tag }} {{ $attributes->merge(['id' => $id, ...$extraAttributes]) }}> +<{{ $tag }} {{ $attributes->merge([...$extraAttributes]) }}> {!! $slot !!} @if($addPermalink === true) From 04aa325e77b9be0f860c95833ef7ced192593995 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 4 Dec 2024 09:32:18 +0100 Subject: [PATCH 04/10] Remove support for custom identifier when it breaks permalinks --- .../framework/tests/Feature/MarkdownHeadingRendererTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php b/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php index d52b02ea5b2..e4a4d24db93 100644 --- a/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php +++ b/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php @@ -111,18 +111,17 @@ public function testHeadingsWithCustomAttributes() public function testHeadingsWithCustomAttributesAndPermalinks() { $markdown = <<<'MARKDOWN' - ## Heading {.custom-class #custom-id} + ## Heading {.custom-class} ### Another Heading {data-test="value"} MARKDOWN; $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); - $this->assertStringContainsString('id="custom-id"', $html); $this->assertStringContainsString('class="custom-class"', $html); $this->assertStringContainsString('data-test="value"', $html); $this->assertSame(<<<'HTML' -

Heading

+

Heading

Another Heading

HTML, $html); From e7be1522416740ad5e8d0f103c4e053f9ff7f191 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 4 Dec 2024 09:34:30 +0100 Subject: [PATCH 05/10] Expect semantic heading identifiers --- .../Feature/MarkdownHeadingRendererTest.php | 22 +++++++++---------- .../tests/Feature/MarkdownServiceTest.php | 2 +- ...aticSiteBuilderDocumentationModuleTest.php | 4 ++-- .../tests/Unit/HeadingRendererUnitTest.php | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php b/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php index e4a4d24db93..cd20a8545f1 100644 --- a/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php +++ b/packages/framework/tests/Feature/MarkdownHeadingRendererTest.php @@ -59,7 +59,7 @@ public function testPermalinksInDocumentationPages() // $this->assertStringContainsString('aria-label="Permalink to this heading"', $html); $this->assertSame(<<<'HTML' -

Documentation Heading

+

Documentation Heading

HTML, $html); } @@ -121,8 +121,8 @@ public function testHeadingsWithCustomAttributesAndPermalinks() $this->assertStringContainsString('data-test="value"', $html); $this->assertSame(<<<'HTML' -

Heading

-

Another Heading

+

Heading

+

Another Heading

HTML, $html); } @@ -144,17 +144,17 @@ public function testPermalinkConfigurationLevels() $html = (new MarkdownService($markdown, DocumentationPage::class))->parse(); $this->assertStringNotContainsString('

H1 No Permalink

assertStringContainsString('

H2 Has PermalinkassertStringContainsString('

H3 Has PermalinkassertStringContainsString('

H4 Has PermalinkassertStringContainsString('