Skip to content
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

fix: fixes a validation issue with Markdown headings including trailing markup #72

Merged
merged 6 commits into from
Dec 2, 2024
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
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