Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
m1k1o
GitHub Repository: m1k1o/neko
Path: blob/master/webpage/src/components/Anchor.tsx
1007 views
1
import useBrokenLinks from '@docusaurus/useBrokenLinks';
2
import React from 'react';
3
4
export function Anchor(props: {id: string}) {
5
useBrokenLinks().collectAnchor(props.id);
6
return <span className="anchorOffset" {...props}/>;
7
}
8
9
// <Def id="cookie.http_only" /> -> <a href="#cookie.http_only"><code id="cookie.http_only">http_only</code></a>
10
export function Def({id, code, ...props}: {id: string, code?: string}) {
11
// split by . and get last part
12
if (code === undefined) {
13
code = id.split('.').pop();
14
}
15
useBrokenLinks().collectAnchor(id);
16
// get current heading id
17
return <a href={`#${id}`} {...props}><code id={id} title={id} className="anchorOffset">{code}</code></a>;
18
}
19
20
// <Opt id="cookie.http_only" /> -> <a href="#cookie.http_only"><code>http_only</code></a>
21
export function Opt({id, code, ...props}: {id: string, code?: string}) {
22
// split by . and get last part
23
if (code === undefined) {
24
code = id.split('.').pop();
25
}
26
// get current heading id
27
return <a href={`#${id}`} {...props}><code title={id} className="anchorOffset">{code}</code></a>;
28
}
29
30