Skip to content

Commit

Permalink
fix: should generate unique aside link id when using different syntax (
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 authored Nov 19, 2024
1 parent 0e693f9 commit b713841
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-bulldogs-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rspress/core': patch
---

release
3 changes: 0 additions & 3 deletions e2e/fixtures/custom-id/doc/guide.mdx

This file was deleted.

15 changes: 15 additions & 0 deletions e2e/fixtures/toc-id/doc/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Guide

## title 1 {#custom-id}

## title 2

## title 2

## `title` 2

## Title 2

## **title** 2

## *title* 2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@rspress-fixture/rspress-custom-id",
"name": "@rspress-fixture/rspress-toc-id",
"version": "1.0.0",
"private": true,
"scripts": {
Expand Down
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions e2e/tests/custom-id.test.ts

This file was deleted.

56 changes: 56 additions & 0 deletions e2e/tests/toc-id.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { expect, test } from '@playwright/test';
import path from 'node:path';
import { getPort, killProcess, runDevCommand } from '../utils/runCommands';

const fixtureDir = path.resolve(__dirname, '../fixtures');

test.describe('custom-id test', async () => {
let appPort;
let app;
test.beforeAll(async () => {
const appDir = path.join(fixtureDir, 'toc-id');
appPort = await getPort();
app = await runDevCommand(appDir, appPort);
});

test.afterAll(async () => {
if (app) {
await killProcess(app);
}
});

test('should generate correct toc id and header anchor', async ({ page }) => {
await page.goto(`http://localhost:${appPort}/`, {
waitUntil: 'networkidle',
});

const anchors = await page.$$('.header-anchor');
const anchorsHref = await Promise.all(
anchors.map(anchor => anchor.getAttribute('href')),
);
expect(anchorsHref).toEqual([
'#guide',
'#custom-id',
'#title-2',
'#title-2-1',
'#title-2-2',
'#title-2-3',
'#title-2-4',
'#title-2-5',
]);

const asides = await page.$$('.aside-link');
const asidesHref = await Promise.all(
asides.map(aside => aside.getAttribute('href')),
);
expect(asidesHref).toEqual([
'#custom-id',
'#title-2',
'#title-2-1',
'#title-2-2',
'#title-2-3',
'#title-2-4',
'#title-2-5',
]);
});
});
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@rsbuild/plugin-less": "~1.1.0",
"@rsbuild/plugin-react": "~1.0.7",
"@rsbuild/plugin-sass": "~1.1.1",
"@rspress/mdx-rs": "0.6.3",
"@rspress/mdx-rs": "0.6.4",
"@rspress/plugin-auto-nav-sidebar": "workspace:*",
"@rspress/plugin-container-syntax": "workspace:*",
"@rspress/plugin-last-updated": "workspace:*",
Expand Down
94 changes: 47 additions & 47 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b713841

Please sign in to comment.