Skip to content

Commit

Permalink
fix link resolution (closes #274)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleds committed Dec 17, 2021
1 parent 270c927 commit a101451
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/typedoc-plugin-markdown/src/resources/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Handlebars from 'handlebars';
import { MarkdownTheme } from '../../theme';
import * as path from 'path';
import * as fs from 'fs';
import { Reflection } from 'typedoc';

const URL_PREFIX = /^(http|ftp)s?:\/\//;
const BRACKETS = /\[\[([^\]]+)\]\]/g;
Expand All @@ -12,7 +13,7 @@ const MEDIA_PATTERN = /media:\/\/([^ "\)\]\}]+)/g;

export default function (theme: MarkdownTheme) {
Handlebars.registerHelper('comment', function (this: string) {
const { project, includes, mediaDirectory } = theme;
const { project, reflection, includes, mediaDirectory } = theme;

function replaceBrackets(text: string) {
return text.replace(
Expand Down Expand Up @@ -51,11 +52,16 @@ export default function (theme: MarkdownTheme) {
return `[${caption}](${target})`;
}

const reflection = project?.findReflectionByName(target);
let targetReflection: Reflection | undefined;
if (reflection) {
targetReflection = reflection.findReflectionByName(target);
} else if (project) {
targetReflection = project.findReflectionByName(target);
}

if (reflection && reflection.url) {
if (targetReflection && targetReflection.url) {
return `[${caption}](${Handlebars.helpers.relativeURL(
reflection.url,
targetReflection.url,
)})`;
} else {
return original;
Expand Down

0 comments on commit a101451

Please sign in to comment.