-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trim trailing slash from slug for heading w markup
- Loading branch information
1 parent
a02d026
commit b1fa5eb
Showing
9 changed files
with
4,642 additions
and
3,176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/starlight-links-validator/tests/fixtures/markup-in-heading/astro.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import starlight from '@astrojs/starlight' | ||
import { defineConfig } from 'astro/config' | ||
|
||
import starlightLinksValidator from 'starlight-links-validator' | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
starlight({ | ||
pagefind: false, | ||
plugins: [starlightLinksValidator()], | ||
title: 'Starlight Links Validator Tests - markup in heading', | ||
}), | ||
], | ||
}) |
10 changes: 10 additions & 0 deletions
10
packages/starlight-links-validator/tests/fixtures/markup-in-heading/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@starlight-links-validator-tests/markup-in-heading", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@astrojs/starlight": "0.26.1", | ||
"astro": "4.8.6", | ||
"starlight-links-validator": "workspace:*" | ||
}, | ||
"private": true | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/starlight-links-validator/tests/fixtures/markup-in-heading/src/content/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { docsSchema } from '@astrojs/starlight/schema' | ||
import { defineCollection } from 'astro:content' | ||
|
||
export const collections = { | ||
docs: defineCollection({ schema: docsSchema() }), | ||
} |
7 changes: 7 additions & 0 deletions
7
...t-links-validator/tests/fixtures/markup-in-heading/src/content/docs/page-two.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: Page Two | ||
--- | ||
|
||
- [Heading with trailing no content markup](/page#heading-with-trailing-no-content-markup) | ||
- [Heading with trailing content markup](/page#heading-with-trailing-content-markup-foo) | ||
- [Heading with complicated markup](/page#-foo-heading-with--foo-complicated-markup-foo) |
15 changes: 15 additions & 0 deletions
15
...ight-links-validator/tests/fixtures/markup-in-heading/src/content/docs/page.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Test | ||
--- | ||
|
||
import { Badge } from '@astrojs/starlight/components' | ||
|
||
## Heading with trailing no content markup <Badge text="x"/> | ||
|
||
## Heading with trailing content markup <Badge text="x">Foo</Badge> | ||
|
||
## <Badge text="x"/> <Badge text="x">Foo</Badge> Heading with <Badge text="x"/> <Badge text="x">Foo</Badge> complicated markup <Badge text="x">Foo</Badge> <Badge text="x"/> | ||
|
||
- [Local link](#heading-with-trailing-no-content-markup) | ||
- [Local link 2](#heading-with-trailing-content-markup-foo) | ||
- [Local link 3](#-foo-heading-with--foo-complicated-markup-foo) |
2 changes: 2 additions & 0 deletions
2
packages/starlight-links-validator/tests/fixtures/markup-in-heading/src/env.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/// <reference types="astro/client" /> | ||
/// <reference path="../.astro/types.d.ts" /> |
19 changes: 19 additions & 0 deletions
19
packages/starlight-links-validator/tests/markup-in-heading.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
import { buildFixture } from './utils' | ||
|
||
/** | ||
* When there is markup in a heading, Astro to renders the heading elements with an id | ||
* that matches the textContent of the heading (excluding the text content of the inner markup elements) | ||
* and then it lowercase & kebabizes it and removes trailing hyphens (but not leading hyphens!) | ||
* | ||
* We use GitHub Slugger to convert the remark heading node string content to a slug. | ||
* Since that util does not remove trailing hyphens, we do so to close the gap with the Astro MD to html renderer | ||
* | ||
* This means Astro sluggifies `## Heading <Foo>` as "heading" for the id attr, but GitHub sluggers renders it as "heading-" | ||
*/ | ||
test('validates links using anchors that refer to headings that contain markup', async () => { | ||
const { status } = await buildFixture('markup-in-heading') | ||
|
||
expect(status).toBe('success') | ||
}) |
Oops, something went wrong.