Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-jobs-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skeletonlabs/skeleton": patch
---

chore: Update Table of Contents to include optional `prefix` and `suffix` parameters
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ interface TOCCrawlerArgs {
scrollTarget?: string;
/** Reload the action when this key value changes. */
key?: unknown;
/* Provide a prefix for ToC links, to help keep them unique. */
prefix?: string;
/* Provide a suffix for ToC links, to help keep them unique. */
suffix?: string;
}

export function tocCrawler(node: HTMLElement, args?: TOCCrawlerArgs) {
Expand Down Expand Up @@ -44,7 +48,9 @@ export function tocCrawler(node: HTMLElement, args?: TOCCrawlerArgs) {
.replaceAll(/[^a-zA-Z0-9 ]/g, '')
.replaceAll(' ', '-')
.toLowerCase();
elemHeading.id = `toc-${newHeadingId}`;
const prefix = args.prefix ? `${args.prefix}-` : '';
const suffix = args.suffix ? `-${args.suffix}` : '';
elemHeading.id = prefix + newHeadingId + suffix;
}
// Push heading data to the permalink array
permalinks.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ let messageFeed = [
</section>

<section class="space-y-4">
<h2 class="h2">Prompt</h2>
<!-- NOTE: id provided to avoid ToC conflict -->
<h2 class="h2" id="prompt-field">Prompt</h2>
<p>
We can utilize a Skeleton <a class="anchor" href="/elements/forms">Input Group</a> to create a custom text prompt.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,24 @@
code={`
<!-- Before: -->
<h2 class="h2">Title One</h2>
<h2 class="h2" id="toc-my-custom-id">Title Two</h2>\n
<h2 class="h2" id="my-custom-id">Title Two</h2>\n
<!-- After: -->
<h2 class="h2" id="title-one">Title One</h2>
<h2 class="h2" id="my-custom-id">Title Two</h2>
`}
/>
<!-- Prefixes and Suffixes -->
<h3 class="h3">Prefixes and Suffixes</h3>
<!-- prettier-ignore -->
<p>
We recommend setting a custom heading (per the instruction above) if a conflict is found within your page. However, you may also hardcode a <code class="code">prefix</code> or <code class="code">suffix</code> to all generated IDs as follows:
</p>
<CodeBlock
language="html"
code={`
<div use:tocCrawler={{ mode: 'generate', prefix: 'foo', suffix: 'bar' }}>\n
<!-- Ex: foo-title-one-bar -->
<!-- Ex: foo-title-two-bar -->
`}
/>
<!-- Ignore Headings -->
Expand Down