Skip to content

Commit 14559d2

Browse files
authored
Merge pull request #23 from ryzrr/feat/example-tags
2 parents a21a41a + 9f35ae1 commit 14559d2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

plugins/theme/helpers/index.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ export default (ctx) => ({
3131
return entries.map(ctx.helpers.typedListItem).join("\n");
3232
},
3333

34+
renderExamples(comment, headingLevel) {
35+
const examples =
36+
comment?.blockTags?.filter((t) => t.tag === "@example") ?? [];
37+
if (!examples.length) return null;
38+
39+
const prefix = "#".repeat(headingLevel + 1);
40+
return examples
41+
.map((tag, index) => {
42+
const heading = `${prefix} Example${examples.length > 1 ? ` ${index + 1}` : ""}`;
43+
const body = ctx.helpers.getCommentParts(tag.content).trim();
44+
return body ? `${heading}\n\n${body}` : null;
45+
})
46+
.filter(Boolean)
47+
.join("\n\n");
48+
},
49+
3450
stabilityBlockquote(comment) {
3551
if (!comment) return null;
3652

plugins/theme/partials/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default (ctx) => ({
6060
headingLevel: options.headingLevel,
6161
showTags: false,
6262
}),
63+
ctx.helpers.renderExamples(comment, options.headingLevel),
6364
]
6465
.filter((x) => typeof x === "string" || Boolean(x))
6566
.join("\n");

0 commit comments

Comments
 (0)