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");