Skip to content

Commit

Permalink
fix: fixes a validation issue with Markdown headings including traili…
Browse files Browse the repository at this point in the history
…ng markup

Co-authored-by: HiDeoo <[email protected]>
  • Loading branch information
jorenbroekema and HiDeoo authored Dec 2, 2024
1 parent a02d026 commit 009be12
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/starlight-links-validator/libs/remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export const remarkStarlightLinksValidator: Plugin<[{ base: string; srcDir: URL
break
}

fileHeadings.push(slugger.slug(content))
// Remove the last trailing hyphen from the slug like Astro does if it exists.
// https://github.com/withastro/astro/blob/74ee2e45ecc9edbe285eadee6d0b94fc47d0d125/packages/integrations/markdoc/src/heading-ids.ts#L21
fileHeadings.push(slugger.slug(content).replace(/-$/, ''))

break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ some content
<LinkButton href="/test/">LinkCard: unknown page</LinkButton>
<LinkButton href="/test/#title">LinkCard: unknown page and hash</LinkButton>
<LinkButton href="#steps">LinkCard: unknown hash</LinkButton>

import { Badge } from '@astrojs/starlight/components'

## Heading with trailing markup <Badge text="x"/>

- [Link to heading with trailing markup](#heading-with-trailing-markup)

## Heading with trailing markup and content <Badge text="x">Foo</Badge>

- [Link to heading with trailing markup and content](#heading-with-trailing-markup-and-content-foo)

## <Badge text="x"/> <Badge text="x">Foo</Badge> Heading with <Badge text="x"/> <Badge text="x">Foo</Badge> complex markup <Badge text="x">Foo</Badge> <Badge text="x"/> <Badge text="y"/>

- [Link to heading with complex markup](#-foo-heading-with--foo-complex-markup-foo-)
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ title: Index
- [Link reference with query string and hash in this page][ref-with-query-string-and-hash-internal]
- [Link reference with query string and hash in another page][ref-with-query-string-and-hash-external]

## Trailing markup

- [Link to heading with trailing markup](/guides/example#heading-with-trailing-markup)
- [Link to heading with trailing markup and content](/guides/example#heading-with-trailing-markup-and-content-foo)
- [Link to heading with complex markup](/guides/example#-foo-heading-with--foo-complex-markup-foo-)

[ref-with-query-string]: /test?query=string
[ref-with-query-string-and-hash-internal]: ?query=string#some-links
[ref-with-query-string-and-hash-external]: /test?query=string#title

0 comments on commit 009be12

Please sign in to comment.