-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.x] Custom Markdown heading renderer #2047
base: new-asset-system
Are you sure you want to change the base?
Conversation
Cursor (Claude) analysis of the three approaches for implementing heading permalinks:1. Original CommonMark Extension Implementation protected function configurePermalinksExtension(): void
{
$this->addExtension(HeadingPermalinkExtension::class);
'fragment_prefix' => '',
$this->config = array_merge([
'heading_permalink' => [
'id_prefix' => '',
'fragment_prefix' => '',
'symbol' => '',
'insert' => 'after',
'min_heading_level' => 2,
'aria_hidden' => false,
],
], $this->config);
} Benefits:
Drawbacks:
2. Full Blade Component Replacement@props(['level' => 1, 'id' => null])
@php
$tag = 'h' . $level;
$id = $id ?? \Illuminate\Support\Str::slug($slot);
@endphp
<{{ $tag }} {{ $attributes->merge(['id' => $id]) }}>
{{ $slot }}
@if(config('markdown.features.permalinks', true))
<a href="#{{ $id }}" class="heading-permalink" aria-label="Permalink for this section"></a>
@endif
</{{ $tag }}> Benefits:
Drawbacks:
3. Permalink-Only Component InjectionExample implementation: // components/heading-permalink.blade.php
@props(['id'])
<a href="#{{ $id }}"
class="heading-permalink"
aria-label="Permalink for this section">
</a> Benefits:
Drawbacks:
RecommendationI recommend using the full Blade component replacement approach (#2) because:
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
@apply w-fit;
}
.prose :is(h1,h2,h3,h4,h5,h6):hover .heading-permalink,
.prose :is(h1,h2,h3,h4,h5,h6):focus .heading-permalink {
@apply opacity-75 grayscale transition-opacity duration-100 ease-out;
}
.heading-permalink {
@apply opacity-0 ml-1 transition-opacity duration-300 ease-linear px-1 scroll-m-4;
}
.heading-permalink::before {
@apply content-['#'];
}
.heading-permalink:hover, .heading-permalink:focus {
@apply opacity-100 grayscale-0;
} The slight performance overhead is negligible for most sites, and the benefits of having full control over the heading structure outweigh the drawbacks. It also makes it easier to add features like custom icons, positioning options, and accessibility improvements in the future. The permalink-only component approach might seem simpler at first, but it introduces complexity in positioning and coordination with existing heading elements. The full component replacement gives us a clean slate to work with while maintaining all the functionality we need. |
61386bd
to
e1ccda8
Compare
packages/framework/resources/views/components/markdown-heading.blade.php
Show resolved
Hide resolved
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## new-asset-system #2047 +/- ##
======================================================
- Coverage 100.00% 99.98% -0.02%
- Complexity 1925 1932 +7
======================================================
Files 195 196 +1
Lines 5122 5131 +9
======================================================
+ Hits 5122 5130 +8
- Misses 0 1 +1 ☔ View full report in Codecov by Sentry. |
Apply fixes from StyleCI Co-Authored-By: StyleCI Bot <[email protected]>
abc3b21
to
6dc0095
Compare
8b78b4d
to
598d9c9
Compare
This reverts commit 039c11a.
Not sure which is best: Which method of heading permalinks is best for a markdown renderer? <h2 id="documentation-heading">Documentation Heading <a href="#documentation-heading" class="heading-permalink" title="Permalink">#</a></h2>
<h2>Documentation Heading<a id="documentation-heading" href="#documentation-heading" class="heading-permalink" title="Permalink">#</a></h2> GPT-4o answer: Both methods can work for generating heading permalinks in a Markdown renderer, but each has its advantages and trade-offs depending on the goals of your renderer. Here's a breakdown of the two approaches: 1st Method: Using
|
3b444a4
to
3c285a7
Compare
Abstract
Changes
HeadingPermalinkExtension
, meaning user added custom options provided to that extension will be ignored. If you for some reason require that extension's custom features, either implement those to the Blade component after publishing it, or disable the Hyde permalink feature from the configuration and add the extension yourself.MarkdownService::withPermalinks
method, see comment