File tree Expand file tree Collapse file tree 2 files changed +149
-106
lines changed
docs/managing-data/core-concepts Expand file tree Collapse file tree 2 files changed +149
-106
lines changed Original file line number Diff line number Diff line change @@ -122,4 +122,41 @@ search. E.g don't search `/docs/observability/schema-design#using-maps` but `/ob
122122reported by the failing broken link checker, the link is most likely found in a snippet which is
123123imported by that page. Find the snippet location from the import statement at the top of the page.
124124
125+ ## Broken anchors
126+
127+ Docusaurus also has a built-in broken anchor checker. Unfortunately it sometimes
128+ can give false positives.
129+
130+ ### linking to spans
131+
132+ Sometimes you want to link to something other than a header. It is logical to
133+ use a span for this purpose. For instance if you want to link to an image.
134+
135+ ```
136+ <span id="page-2-0"></span><img src={image_02}/>
137+
138+ As shown by [Figure 2,](#page-2-0)...
139+ ```
140+
141+ Unfortunately, docusaurus' anchor checker will throw an error on this link:
142+
143+ ``` response
144+ - Broken anchor on source page path = /docs/academic_overview:
145+ -> linking to #page-1-0 (resolved as: /docs/academic_overview#page-1-0)
146+ ```
147+
148+ Follow the steps below for the workaround:
149+
150+ - change the file from ` .md ` to ` .mdx `
151+ - import ` useBrokenLinks ` hook with ` import useBrokenLinks from "@docusaurus/useBrokenLinks"; `
152+ - add the following component to the page:
153+
154+ ```
155+ export function Anchor(props) {
156+ useBrokenLinks().collectAnchor(props.id);
157+ return <span style={{scrollMarginTop: "var(--ifm-navbar-height)"}} {...props}/>;
158+ }
159+ ```
160+ - Replace ` <span id="some-id"></span> ` with ` Anchor id="some-id"/> `
161+
125162
You can’t perform that action at this time.
0 commit comments