Skip to content

Commit

Permalink
Merge pull request #37 from HiDeoo/hd-0-11-0
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Apr 15, 2024
2 parents 55e4ef2 + b2e40c1 commit 9071dc6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/src/content/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ni starlight-typedoc typedoc typedoc-plugin-markdown@next
</Tabs>

:::note
The Starlight TypeDoc package requires at least the version `4.0.0-next.45` of `typedoc-plugin-markdown`, hence the `@next` tag in the installation command.
The Starlight TypeDoc package requires at least the version `4.0.0-next.54` of `typedoc-plugin-markdown`, hence the `@next` tag in the installation command.
:::

## Add the plugin
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"sharp": "0.32.6",
"starlight-typedoc": "workspace:*",
"typedoc": "0.25",
"typedoc-plugin-markdown": "4.0.0-next.45",
"typedoc-plugin-markdown": "4.0.0-next.54",
"typedoc-plugin-mdn-links": "3.0.3"
},
"engines": {
Expand Down
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
2 changes: 1 addition & 1 deletion packages/starlight-typedoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@astrojs/starlight": ">=0.15.0",
"astro": ">=4.0.0",
"typedoc": ">=0.25.0",
"typedoc-plugin-markdown": ">=4.0.0-next.45"
"typedoc-plugin-markdown": ">=4.0.0-next.54"
},
"engines": {
"node": ">=18.14.1"
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9071dc6

Please sign in to comment.