Skip to content

Commit 5d9a51d

Browse files
committed
markdown helper now accepts CommentDisplayPart
Ref: #2004
1 parent 6de1e38 commit 5d9a51d

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Added support for using the comment directly before a constructor parameter that declares a property as the property comment, #2019.
77
- Improved schema generation to give better autocomplete for the `sort` option.
88
- Optional properties are now visually distinguished in the index/sidebar by rendering `prop` as `prop?`, #2023.
9+
- `DefaultThemeRenderContext.markdown` now also accepts a `CommentDisplayPart[]` for rendering, #2004.
910

1011
### Bug Fixes
1112

src/lib/output/themes/default/DefaultThemeRenderContext.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { RendererHooks } from "../..";
2-
import type { ReferenceType, Reflection } from "../../../models";
3-
import type { Options } from "../../../utils";
2+
import type {
3+
CommentDisplayPart,
4+
ReferenceType,
5+
Reflection,
6+
} from "../../../models";
7+
import type { NeverIfInternal, Options } from "../../../utils";
8+
import { displayPartsToMarkdown } from "../lib";
49
import type { DefaultTheme } from "./DefaultTheme";
510
import { defaultLayout } from "./layouts/default";
611
import { index } from "./partials";
@@ -58,7 +63,14 @@ export class DefaultThemeRenderContext {
5863

5964
urlTo = (reflection: Reflection) => this.relativeURL(reflection.url);
6065

61-
markdown = (md: string | undefined) => {
66+
markdown = (
67+
md: readonly CommentDisplayPart[] | NeverIfInternal<string | undefined>
68+
) => {
69+
if (md instanceof Array) {
70+
return this.theme.markedPlugin.parseMarkdown(
71+
displayPartsToMarkdown(md, this.urlTo)
72+
);
73+
}
6274
return md ? this.theme.markedPlugin.parseMarkdown(md) : "";
6375
};
6476

src/lib/output/themes/default/partials/comment.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
22
import { JSX, Raw } from "../../../../utils";
33
import type { Reflection } from "../../../../models";
4-
import { camelToTitleCase, displayPartsToMarkdown } from "../../lib";
4+
import { camelToTitleCase } from "../../lib";
55

6-
export function comment({ markdown, urlTo }: DefaultThemeRenderContext, props: Reflection) {
6+
export function comment({ markdown }: DefaultThemeRenderContext, props: Reflection) {
77
if (!props.comment?.hasVisibleComponent()) return;
88

99
// Note: Comment modifiers are handled in `renderFlags`
1010

1111
return (
1212
<div class="tsd-comment tsd-typography">
13-
<Raw html={markdown(displayPartsToMarkdown(props.comment.summary, urlTo))} />
13+
<Raw html={markdown(props.comment.summary)} />
1414
{props.comment.blockTags.map((item) => (
1515
<>
1616
<h3>{camelToTitleCase(item.tag.substring(1))}</h3>
17-
<Raw html={markdown(displayPartsToMarkdown(item.content, urlTo))} />
17+
<Raw html={markdown(item.content)} />
1818
</>
1919
))}
2020
</div>

src/lib/output/themes/default/partials/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { classNames, displayPartsToMarkdown, renderName } from "../../lib";
1+
import { classNames, renderName } from "../../lib";
22
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33
import { JSX, Raw } from "../../../../utils";
44
import { ContainerReflection, DeclarationReflection, ReflectionCategory, ReflectionKind } from "../../../../models";
@@ -73,7 +73,7 @@ export function index(context: DefaultThemeRenderContext, props: ContainerReflec
7373
props.readme?.length !== 0 && (
7474
<section class="tsd-panel-group">
7575
<section class="tsd-panel tsd-typography">
76-
<Raw html={context.markdown(displayPartsToMarkdown(props.readme || [], context.urlTo))} />
76+
<Raw html={context.markdown(props.readme || [])} />
7777
</section>
7878
</section>
7979
)}

src/lib/output/themes/default/templates/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
22
import type { ProjectReflection } from "../../../../models";
33
import type { PageEvent } from "../../../events";
44
import { JSX, Raw } from "../../../../utils";
5-
import { displayPartsToMarkdown } from "../../lib";
65

7-
export const indexTemplate = ({ markdown, urlTo }: DefaultThemeRenderContext, props: PageEvent<ProjectReflection>) => (
6+
export const indexTemplate = ({ markdown }: DefaultThemeRenderContext, props: PageEvent<ProjectReflection>) => (
87
<div class="tsd-panel tsd-typography">
9-
<Raw html={markdown(displayPartsToMarkdown(props.model.readme || [], urlTo))} />
8+
<Raw html={markdown(props.model.readme || [])} />
109
</div>
1110
);

src/lib/output/themes/lib.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ export function camelToTitleCase(text: string) {
117117
return text.substring(0, 1).toUpperCase() + text.substring(1).replace(/[a-z][A-Z]/g, (x) => `${x[0]} ${x[1]}`);
118118
}
119119

120-
export function displayPartsToMarkdown(parts: CommentDisplayPart[], urlTo: DefaultThemeRenderContext["urlTo"]) {
120+
export function displayPartsToMarkdown(
121+
parts: readonly CommentDisplayPart[],
122+
urlTo: DefaultThemeRenderContext["urlTo"]
123+
) {
121124
const result: string[] = [];
122125

123126
for (const part of parts) {

0 commit comments

Comments
 (0)