Skip to content

Commit d7f1531

Browse files
committed
chore: header-anchor rename to rp-header-anchor
1 parent 6ee0e74 commit d7f1531

File tree

14 files changed

+62
-33
lines changed

14 files changed

+62
-33
lines changed

packages/core/src/node/mdx/rehypePlugins/__snapshots__/headerAnchor.test.ts.snap

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ exports[`rehypeHeadAnchor > basic 1`] = `
55
/*prettier-ignore-end*/
66
import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
77
import {useMDXComponents as _provideComponents} from "@mdx-js/react";
8+
import {Callout as $$$Callout$$$} from "@theme";
89
function _createMdxContent(props) {
910
const _components = {
1011
a: "a",
@@ -20,47 +21,47 @@ function _createMdxContent(props) {
2021
children: [_jsxs(_components.h1, {
2122
id: "guide",
2223
children: [_jsx(_components.a, {
23-
className: "header-anchor",
24+
className: "rp-header-anchor",
2425
"aria-hidden": "true",
2526
href: "#guide",
2627
children: "#"
2728
}), "Guide"]
2829
}), "\\n", _jsxs(_components.h2, {
2930
id: "custom-id",
3031
children: [_jsx(_components.a, {
31-
className: "header-anchor",
32+
className: "rp-header-anchor",
3233
"aria-hidden": "true",
3334
href: "#custom-id",
3435
children: "#"
3536
}), "title 1"]
3637
}), "\\n", _jsxs(_components.h2, {
3738
id: "custom-id",
3839
children: [_jsx(_components.a, {
39-
className: "header-anchor",
40+
className: "rp-header-anchor",
4041
"aria-hidden": "true",
4142
href: "#custom-id",
4243
children: "#"
4344
}), "title 1"]
4445
}), "\\n", _jsxs(_components.h2, {
4546
id: "title-2",
4647
children: [_jsx(_components.a, {
47-
className: "header-anchor",
48+
className: "rp-header-anchor",
4849
"aria-hidden": "true",
4950
href: "#title-2",
5051
children: "#"
5152
}), "title 2"]
5253
}), "\\n", _jsxs(_components.h2, {
5354
id: "title-2-1",
5455
children: [_jsx(_components.a, {
55-
className: "header-anchor",
56+
className: "rp-header-anchor",
5657
"aria-hidden": "true",
5758
href: "#title-2-1",
5859
children: "#"
5960
}), "title 2"]
6061
}), "\\n", _jsxs(_components.h2, {
6162
id: "title-2-2",
6263
children: [_jsx(_components.a, {
63-
className: "header-anchor",
64+
className: "rp-header-anchor",
6465
"aria-hidden": "true",
6566
href: "#title-2-2",
6667
children: "#"
@@ -70,15 +71,15 @@ function _createMdxContent(props) {
7071
}), "\\n", _jsxs(_components.h2, {
7172
id: "title-2-3",
7273
children: [_jsx(_components.a, {
73-
className: "header-anchor",
74+
className: "rp-header-anchor",
7475
"aria-hidden": "true",
7576
href: "#title-2-3",
7677
children: "#"
7778
}), "Title 2"]
7879
}), "\\n", _jsxs(_components.h2, {
7980
id: "title-2-4",
8081
children: [_jsx(_components.a, {
81-
className: "header-anchor",
82+
className: "rp-header-anchor",
8283
"aria-hidden": "true",
8384
href: "#title-2-4",
8485
children: "#"
@@ -88,7 +89,7 @@ function _createMdxContent(props) {
8889
}), "\\n", "\\n", _jsxs(_components.h2, {
8990
id: "title-2-5",
9091
children: [_jsx(_components.a, {
91-
className: "header-anchor",
92+
className: "rp-header-anchor",
9293
"aria-hidden": "true",
9394
href: "#title-2-5",
9495
children: "#"
@@ -120,6 +121,7 @@ MDXContent.__RSPRESS_PAGE_META["index.mdx"] = {"toc":[{"id":"custom-id","text":"
120121
exports[`rehypeHeadAnchor > should render inline code in title 1`] = `
121122
"import {jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
122123
import {useMDXComponents as _provideComponents} from "@mdx-js/react";
124+
import {Callout as $$$Callout$$$} from "@theme";
123125
function _createMdxContent(props) {
124126
const _components = {
125127
a: "a",
@@ -131,7 +133,7 @@ function _createMdxContent(props) {
131133
return _jsxs(_components.h1, {
132134
id: "hello-world-inline-code",
133135
children: [_jsx(_components.a, {
134-
className: "header-anchor",
136+
className: "rp-header-anchor",
135137
"aria-hidden": "true",
136138
href: "#hello-world-inline-code",
137139
children: "#"
@@ -162,6 +164,7 @@ MDXContent.__RSPRESS_PAGE_META["inline-code.mdx"] = {"toc":[],"title":"Hello Wor
162164
exports[`rehypeHeadAnchor > should support custom id 1`] = `
163165
"import {jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
164166
import {useMDXComponents as _provideComponents} from "@mdx-js/react";
167+
import {Callout as $$$Callout$$$} from "@theme";
165168
function _createMdxContent(props) {
166169
const _components = {
167170
a: "a",
@@ -173,7 +176,7 @@ function _createMdxContent(props) {
173176
return _jsxs(_components.h1, {
174177
id: "custom-id",
175178
children: [_jsx(_components.a, {
176-
className: "header-anchor",
179+
className: "rp-header-anchor",
177180
"aria-hidden": "true",
178181
href: "#custom-id",
179182
children: "#"
@@ -204,6 +207,7 @@ MDXContent.__RSPRESS_PAGE_META["inline-code.mdx"] = {"toc":[],"title":"Hello Wor
204207
exports[`rehypeHeadAnchor > should support mdx component with trim 1`] = `
205208
"import {jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
206209
import {useMDXComponents as _provideComponents} from "@mdx-js/react";
210+
import {Callout as $$$Callout$$$} from "@theme";
207211
function _createMdxContent(props) {
208212
const _components = {
209213
a: "a",
@@ -215,7 +219,7 @@ function _createMdxContent(props) {
215219
return _jsxs(_components.h1, {
216220
id: "hello-world",
217221
children: [_jsx(_components.a, {
218-
className: "header-anchor",
222+
className: "rp-header-anchor",
219223
"aria-hidden": "true",
220224
href: "#hello-world",
221225
children: "#"

packages/core/src/node/mdx/rehypePlugins/headerAnchor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function create(node: Element): Element {
6262
type: 'element',
6363
tagName: 'a',
6464
properties: {
65-
class: 'header-anchor',
65+
class: 'rp-header-anchor',
6666
ariaHidden: 'true',
6767
href: `#${node.properties!.id}`,
6868
},

packages/core/src/node/mdx/remarkPlugins/__snapshots__/containerSyntax.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ function _createMdxContent(props) {
891891
children: _jsxs(_components.h1, {
892892
id: "please-read-this-note",
893893
children: [_jsx(_components.a, {
894-
className: "header-anchor",
894+
className: "rp-header-anchor",
895895
"aria-hidden": "true",
896896
href: "#please-read-this-note",
897897
children: "#"

packages/core/src/node/mdx/remarkPlugins/__snapshots__/fileCodeBlock.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`remarkFileCodeBlock > basic 1`] = `
44
"import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
55
import {useMDXComponents as _provideComponents} from "@mdx-js/react";
6+
import {Callout as $$$Callout$$$} from "@theme";
67
function _createMdxContent(props) {
78
const _components = {
89
code: "code",

packages/core/src/node/mdx/remarkPlugins/__snapshots__/image.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ exports[`mdx > basic 1`] = `
55
import {useMDXComponents as _provideComponents} from "@mdx-js/react";
66
import image0 from "./test3.jpg";
77
import image1 from "./test4.png";
8+
import {Callout as $$$Callout$$$} from "@theme";
89
function _createMdxContent(props) {
910
const _components = {
1011
img: "img",

packages/core/src/node/mdx/remarkPlugins/__snapshots__/link.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`mdx > basic 1`] = `
44
"/*jsx link will not be transformed*/
55
import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
66
import {useMDXComponents as _provideComponents} from "@mdx-js/react";
7+
import {Callout as $$$Callout$$$} from "@theme";
78
function _createMdxContent(props) {
89
const _components = {
910
a: "a",

packages/plugin-api-docgen/static/global-components/API.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function create(node: Element): Element {
6060
type: 'element',
6161
tagName: 'a',
6262
properties: {
63-
class: 'header-anchor',
63+
class: 'rp-header-anchor',
6464
ariaHidden: 'true',
6565
href: `#${node.properties!.id}`,
6666
},

packages/theme-default/src/components/Aside/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect } from 'react';
44
import { scrollToTarget } from '../../logic/sideEffects';
55
import { ReadPercent } from '../ReadPercent';
66
import './index.scss';
7+
import { useDynamicToc } from '../Toc/useDynamicToc';
78
import { ScrollToTop } from './ScrollToTop';
89

910
export function Aside() {
@@ -18,7 +19,6 @@ export function Aside() {
1819

1920
useEffect(() => {
2021
const decodedHash = decodeURIComponent(window.location.hash);
21-
console.log('decodedHash', decodedHash);
2222
if (decodedHash.length === 0) {
2323
window.scrollTo(0, 0);
2424
} else {
@@ -30,6 +30,12 @@ export function Aside() {
3030
}
3131
}, [pathname]);
3232

33+
const headers = useDynamicToc();
34+
35+
if (headers.length === 0) {
36+
return <></>;
37+
}
38+
3339
return (
3440
<div className="rp-aside">
3541
<div className="rp-aside__title">

packages/theme-default/src/components/Aside/processTitleElement.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
export function processTitleElement(element: Element): Element {
77
const elementClone = element.cloneNode(true) as Element;
88

9-
// 1. remove .header-anchor
10-
const anchorElement = elementClone.querySelector('.header-anchor');
9+
// 1. remove .rp-header-anchor
10+
const anchorElement = elementClone.querySelector('.rp-header-anchor');
1111

1212
if (anchorElement) {
1313
elementClone.removeChild(anchorElement);
1414
}
1515

1616
// 2. delete ".rspress-toc-exclude" element
17-
const excludeElements = elementClone.querySelectorAll('.rspress-toc-exclude');
17+
const excludeElements = elementClone.querySelectorAll(
18+
'.rspress-toc-exclude,.rp-toc-exclude',
19+
);
1820
excludeElements.forEach(excludeElement => {
1921
const parentElement = excludeElement.parentElement;
2022
if (parentElement) {

packages/theme-default/src/components/DocContent/FallbackHeading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function FallbackHeading({
3434
titleSlug && (
3535
<Element id={titleSlug}>
3636
<span {...renderInlineMarkdown(title)}></span>
37-
<A className="header-anchor" href={`#${titleSlug}`} aria-hidden>
37+
<A className="rp-header-anchor" href={`#${titleSlug}`} aria-hidden>
3838
#
3939
</A>
4040
</Element>

0 commit comments

Comments
 (0)