fix(website): always link in TypeAlias (#10105)

* fix(website): always link in TypeAlias

* fix: use div instead span for DocParagraph
This commit is contained in:
Qjuh
2024-02-04 01:39:00 +01:00
committed by GitHub
parent 56943a72f4
commit bc9b487eb1
4 changed files with 21 additions and 25 deletions

View File

@@ -4,7 +4,7 @@ import { useMemo } from 'react';
import { ExcerptText } from '~/components/ExcerptText'; import { ExcerptText } from '~/components/ExcerptText';
import { DocumentationSection } from './DocumentationSection'; import { DocumentationSection } from './DocumentationSection';
export type UnionMember = ExcerptToken[]; export type UnionMember = readonly ExcerptToken[];
export function UnionMembersSection({ export function UnionMembersSection({
item, item,

View File

@@ -25,9 +25,9 @@ export function TSDoc({ item, tsdoc }: { readonly item: ApiItem; readonly tsdoc:
case DocNodeKind.Section: case DocNodeKind.Section:
case DocNodeKind.Paragraph: case DocNodeKind.Paragraph:
return ( return (
<span className="break-words leading-relaxed" key={idx}> <div className="break-words leading-relaxed" key={idx}>
{(tsdoc as DocNodeContainer).nodes.map((node, idx) => createNode(node, idx))} {(tsdoc as DocNodeContainer).nodes.map((node, idx) => createNode(node, idx))}
</span> </div>
); );
case DocNodeKind.SoftBreak: case DocNodeKind.SoftBreak:
return <Fragment key={idx} />; return <Fragment key={idx} />;

View File

@@ -13,16 +13,10 @@ export function TypeAlias({ item }: { readonly item: ApiTypeAlias }) {
let depth = 0; let depth = 0;
for (const token of item.typeExcerpt.spannedTokens) { for (const token of item.typeExcerpt.spannedTokens) {
if (token.text.includes('?')) { if (token.text.includes('?')) {
return []; return [item.typeExcerpt.spannedTokens];
} }
if (token.text.includes('<')) { depth += token.text.split('<').length - token.text.split('>').length;
depth++;
}
if (token.text.includes('>')) {
depth--;
}
if (token.text.trim() === '|' && depth === 0) { if (token.text.trim() === '|' && depth === 0) {
if (currentUnionMember.length) { if (currentUnionMember.length) {
@@ -47,7 +41,7 @@ export function TypeAlias({ item }: { readonly item: ApiTypeAlias }) {
} }
} }
if (currentUnionMember.length && union.length) { if (currentUnionMember.length) {
union.push(currentUnionMember); union.push(currentUnionMember);
} }

View File

@@ -1690,20 +1690,22 @@ export class ApiModelGenerator {
} }
private _fixLinkTags(input?: string): string | undefined { private _fixLinkTags(input?: string): string | undefined {
return input?.replaceAll(linkRegEx, (_match, _p1, _p2, _p3, _p4, _p5, _offset, _string, groups) => { return input
let target = groups.class ?? groups.url; ?.replaceAll(linkRegEx, (_match, _p1, _p2, _p3, _p4, _p5, _offset, _string, groups) => {
const external = this._jsDocJson?.externals.find((external) => groups.class && external.name === groups.class); let target = groups.class ?? groups.url;
const match = /discord-api-types-(?<type>[^#]*?)(?:#|\/(?<kind>[^#/]*)\/)(?<name>[^/}]*)}$/.exec( const external = this._jsDocJson?.externals.find((external) => groups.class && external.name === groups.class);
external?.see?.[0] ?? '', const match = /discord-api-types-(?<type>[^#]*?)(?:#|\/(?<kind>[^#/]*)\/)(?<name>[^/}]*)}$/.exec(
); external?.see?.[0] ?? '',
if (match) { );
target = `discord-api-types#(${match.groups!.name}:${ if (match) {
/^v\d+$/.test(match.groups!.type!) ? match.groups!.kind : 'type' target = `discord-api-types#(${match.groups!.name}:${
})`; /^v\d+$/.test(match.groups!.type!) ? match.groups!.kind : 'type'
} })`;
}
return `{@link ${target}${groups.prop ? `.${groups.prop}` : ''}${groups.name ? ` |${groups.name}` : ''}}`; return `{@link ${target}${groups.prop ? `.${groups.prop}` : ''}${groups.name ? ` |${groups.name}` : ''}}`;
}); })
.replaceAll('* ', '\n * * ');
} }
private _mapVarType(typey: DocgenVarTypeJson): IExcerptToken[] { private _mapVarType(typey: DocgenVarTypeJson): IExcerptToken[] {