From 9f35ae1662c7b76b164411cec885f28e5659c7d1 Mon Sep 17 00:00:00 2001 From: Nikhil Kumar Rajak Date: Sat, 14 Mar 2026 06:58:12 +0000 Subject: [PATCH] feat(theme): render @example JSDoc tags in member bodies Resolves #5. Adds a renderExamples() helper that extracts @example block tags from TypeDoc reflections and appends them as headed sections (at headingLevel + 1) after the member description. Multiple @example tags are rendered with numbered headings (Example 1, Example 2, ...). Empty example bodies are filtered out. --- plugins/theme/helpers/index.mjs | 16 ++++++++++++++++ plugins/theme/partials/index.mjs | 1 + 2 files changed, 17 insertions(+) diff --git a/plugins/theme/helpers/index.mjs b/plugins/theme/helpers/index.mjs index 880933e..eff4a8f 100644 --- a/plugins/theme/helpers/index.mjs +++ b/plugins/theme/helpers/index.mjs @@ -31,6 +31,22 @@ export default (ctx) => ({ return entries.map(ctx.helpers.typedListItem).join("\n"); }, + renderExamples(comment, headingLevel) { + const examples = + comment?.blockTags?.filter((t) => t.tag === "@example") ?? []; + if (!examples.length) return null; + + const prefix = "#".repeat(headingLevel + 1); + return examples + .map((tag, index) => { + const heading = `${prefix} Example${examples.length > 1 ? ` ${index + 1}` : ""}`; + const body = ctx.helpers.getCommentParts(tag.content).trim(); + return body ? `${heading}\n\n${body}` : null; + }) + .filter(Boolean) + .join("\n\n"); + }, + stabilityBlockquote(comment) { if (!comment) return null; diff --git a/plugins/theme/partials/index.mjs b/plugins/theme/partials/index.mjs index 56463fb..b297783 100644 --- a/plugins/theme/partials/index.mjs +++ b/plugins/theme/partials/index.mjs @@ -60,6 +60,7 @@ export default (ctx) => ({ headingLevel: options.headingLevel, showTags: false, }), + ctx.helpers.renderExamples(comment, options.headingLevel), ] .filter((x) => typeof x === "string" || Boolean(x)) .join("\n");