Skip to content

Commit

Permalink
fix: Fixes a link rendering issue with latest versions of `typedoc-pl…
Browse files Browse the repository at this point in the history
…ugin-markdown`
  • Loading branch information
HiDeoo committed Apr 15, 2024
1 parent 7816062 commit b2e40c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/starlight-typedoc/libs/starlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export function getRelativeURL(url: string, baseUrl: string, pageUrl?: string):

const currentDirname = path.dirname(pageUrl ?? '')
const urlDirname = path.dirname(url)
const relativeUrl = currentDirname === urlDirname ? url : path.posix.join(currentDirname, url)
const relativeUrl = currentDirname === urlDirname ? url : path.posix.relative(currentDirname, url)

const filePath = path.parse(relativeUrl)
const [, anchor] = filePath.base.split('#')
Expand Down
29 changes: 14 additions & 15 deletions packages/starlight-typedoc/libs/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,27 @@ export class StarlightTypeDocTheme extends MarkdownTheme {
class StarlightTypeDocThemeRenderContext extends MarkdownThemeRenderContext {
#markdownThemeRenderContext: MarkdownThemeRenderContext

constructor(theme: MarkdownTheme, event: PageEvent<Reflection> | null, options: Options) {
constructor(theme: MarkdownTheme, event: PageEvent<Reflection>, options: Options) {
super(theme, event, options)

this.#markdownThemeRenderContext = new MarkdownThemeRenderContext(theme, event, options)
}

override parseUrl = (url: string) => {
const outputDirectory = this.options.getValue('starlight-typedoc-output')
const baseUrl = typeof outputDirectory === 'string' ? outputDirectory : ''
override helpers: MarkdownThemeRenderContext['helpers'] = {
// @ts-expect-error https://github.com/tgreyuk/typedoc-plugin-markdown/blob/2bc4136a364c1d1ab44789d6148cd19c425ce63c/docs/pages/docs/customizing-output.mdx#custom-theme
...this.helpers,
getRelativeUrl: (url: string) => {
const outputDirectory = this.options.getValue('starlight-typedoc-output')
const baseUrl = typeof outputDirectory === 'string' ? outputDirectory : ''

return getRelativeURL(url, baseUrl, this.page?.url)
return getRelativeURL(url, baseUrl, this.page.url)
},
}

override partials: MarkdownThemeRenderContext['partials'] = {
// @ts-expect-error - https://github.com/tgreyuk/typedoc-plugin-markdown/blob/37f9de583074e725159f57d70f3ed130007a964c/docs/pages/customizing/custom-theme.mdx
// @ts-expect-error https://github.com/tgreyuk/typedoc-plugin-markdown/blob/2bc4136a364c1d1ab44789d6148cd19c425ce63c/docs/pages/docs/customizing-output.mdx#custom-theme
...this.partials,
comment: (comment, headingLevel, showSummary, showTags) => {
comment: (comment, options) => {
const filteredComment = { ...comment } as Comment
filteredComment.blockTags = []
filteredComment.modifierTags = new Set<`@${string}`>()
Expand All @@ -66,14 +70,9 @@ class StarlightTypeDocThemeRenderContext extends MarkdownThemeRenderContext {

filteredComment.summary = comment.summary.map((part) => this.#parseCommentDisplayPart(part))

let markdown = this.#markdownThemeRenderContext.partials.comment(
filteredComment,
headingLevel,
showSummary,
showTags,
)
let markdown = this.#markdownThemeRenderContext.partials.comment(filteredComment, options)

if (showTags === true && showSummary === false) {
if (options?.showSummary === false) {
return markdown
}

Expand Down Expand Up @@ -111,7 +110,7 @@ class StarlightTypeDocThemeRenderContext extends MarkdownThemeRenderContext {
) {
return {
...part,
target: this.parseUrl(
target: this.helpers.getRelativeUrl(
path.posix.join(this.options.getValue('entryPointStrategy') === 'packages' ? '../..' : '..', part.target.url),
),
}
Expand Down

0 comments on commit b2e40c1

Please sign in to comment.