Skip to content

Commit

Permalink
fix: restrict heading deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackman99 committed Mar 5, 2024
1 parent 21cd863 commit aa8162c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-plums-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltepress/theme-default": patch
---

fix: restrict heading depth
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ All headings in your page md files would render the toc on the right of the page
As you currently can see on every page
And multi levels are supported

# Level 1 heading

```md

## Heading1
### Some heading contains special characters&?:/.
### Heading1 nested2
Expand Down
5 changes: 4 additions & 1 deletion packages/theme-default/src/components/PageLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
{/if}

<style>
:global(.theme-default--page-layout h1 .svp-title-anchor),
:global(.theme-default--page-layout h2 .svp-title-anchor),
:global(.theme-default--page-layout h3 .svp-title-anchor),
:global(.theme-default--page-layout h4 .svp-title-anchor),
Expand All @@ -91,6 +92,7 @@
:global(.theme-default--page-layout h2 .svp-title-anchor) {
transform: translate(-100%, calc((-100% + 1rem) / 2));
}
:global(.theme-default--page-layout h1),
:global(.theme-default--page-layout h2),
:global(.theme-default--page-layout h3),
:global(.theme-default--page-layout h4),
Expand All @@ -101,12 +103,13 @@
:global(.theme-default--page-layout h2) {
--at-apply: 'border-t-solid border-t border-light-7 dark:border-gray-7 pt-4 mt-8 mb-4';
}
:global(.theme-default--page-layout h1:hover .svp-title-anchor),
:global(.theme-default--page-layout h2:hover .svp-title-anchor),
:global(.theme-default--page-layout h3:hover .svp-title-anchor),
:global(.theme-default--page-layout h4:hover .svp-title-anchor),
:global(.theme-default--page-layout h5:hover .svp-title-anchor),
:global(.theme-default--page-layout h6:hover .svp-title-anchor) {
--at-apply: pointer-events-auto opacity-100;
--at-apply: 'pointer-events-auto opacity-100';
}
.content {
--at-apply: 'sm:w-[45vw] mx-auto pb-8 sm:pb-28 w-[90vw]';
Expand Down
7 changes: 5 additions & 2 deletions packages/theme-default/src/components/Toc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import { afterNavigate } from '$app/navigation'
import { page } from '$app/stores'
/**
* @type {Array<import('../markdown/anchors').Anchor>}
*/
export let anchors = []
let scrollY
Expand Down Expand Up @@ -68,10 +71,10 @@
{#each anchors as an, i}
{@const active = activeIdx === i}
<a
href={`#${an.slugId}`}
href="#${an.slugId}"
class="item"
class:active
style={`--heading-depth: ${an.depth};`}
style="--heading-depth: ${an.depth < 2 ? 2 : an.depth};"
>
{an.title}
</a>
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-default/src/markdown/anchors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Plugin } from 'unified'
import { visit } from 'unist-util-visit'

interface Anchor {
export interface Anchor {
slugId: string
title: string
depth: number
Expand Down

0 comments on commit aa8162c

Please sign in to comment.