From e5a40d58050cad370c82fc5ef897f8d7268e1d13 Mon Sep 17 00:00:00 2001 From: tgreyuk Date: Fri, 12 Nov 2021 22:44:02 +0000 Subject: [PATCH] fix: Added support for third party symbols (#263) --- .../src/render-utils.ts | 2 ++ .../helpers/attemptExternalResolution.ts | 13 ++++++++++ .../src/resources/helpers/type.ts | 25 +++++++++++++------ 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 packages/typedoc-plugin-markdown/src/resources/helpers/attemptExternalResolution.ts diff --git a/packages/typedoc-plugin-markdown/src/render-utils.ts b/packages/typedoc-plugin-markdown/src/render-utils.ts index 03783a065..2729c54d2 100644 --- a/packages/typedoc-plugin-markdown/src/render-utils.ts +++ b/packages/typedoc-plugin-markdown/src/render-utils.ts @@ -1,6 +1,7 @@ import * as fs from 'fs'; import * as Handlebars from 'handlebars'; import * as path from 'path'; +import attemptExternalResolution from './resources/helpers/attemptExternalResolution'; import breadcrumbsHelper from './resources/helpers/breadcrumbs'; import commentHelper from './resources/helpers/comment'; import commentsHelper from './resources/helpers/comments'; @@ -54,6 +55,7 @@ export function registerPartials() { } export function registerHelpers(theme: MarkdownTheme) { + attemptExternalResolution(theme); breadcrumbsHelper(theme); commentHelper(theme); commentsHelper(); diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/attemptExternalResolution.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/attemptExternalResolution.ts new file mode 100644 index 000000000..95975649f --- /dev/null +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/attemptExternalResolution.ts @@ -0,0 +1,13 @@ +import * as Handlebars from 'handlebars'; +import type * as ts from 'typescript'; + +import { MarkdownTheme } from '../../theme'; + +export default function (theme: MarkdownTheme) { + Handlebars.registerHelper( + 'attemptExternalResolution', + function (symbol: ts.Symbol | undefined) { + return theme.owner.attemptExternalResolution(symbol); + }, + ); +} diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/type.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/type.ts index c73fff43d..86ca7d880 100644 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/type.ts +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/type.ts @@ -193,14 +193,23 @@ export function getFunctionType(modelSignatures: SignatureReflection[]) { function getReferenceType(model: ReferenceType, emphasis) { if (model.reflection || (model.name && model.typeArguments)) { - const reflection = - model.reflection && model.reflection.url - ? [ - `[${`\`${model.reflection.name}\``}](${Handlebars.helpers.relativeURL( - model.reflection.url, - )})`, - ] - : [`\`${model.name}\``]; + const reflection: string[] = []; + if (model.reflection?.url) { + reflection.push( + `[${`\`${model.reflection.name}\``}](${Handlebars.helpers.relativeURL( + model.reflection.url, + )})`, + ); + } else { + const externalUrl = Handlebars.helpers.attemptExternalResolution( + model.getSymbol(), + ); + reflection.push( + externalUrl + ? `[${`\`${model.name}\``}](${externalUrl})` + : `\`${model.name}\``, + ); + } if (model.typeArguments && model.typeArguments.length > 0) { reflection.push( `<${model.typeArguments