From 8e4172ba28381fd20eaa598234c63186631fd6fc Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Wed, 20 Sep 2023 02:47:34 +0700 Subject: docs: show examples for modules (#2406) Co-authored-by: ST-DDT --- scripts/apidoc/moduleMethods.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'scripts/apidoc/moduleMethods.ts') diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts index 359282dc..89f234db 100644 --- a/scripts/apidoc/moduleMethods.ts +++ b/scripts/apidoc/moduleMethods.ts @@ -5,10 +5,12 @@ import type { } from 'typedoc'; import type { Method } from '../../docs/.vitepress/components/api-docs/method'; import { writeApiDocsModule } from './apiDocsWriter'; +import { codeToHtml } from './markdown'; import { analyzeSignature } from './signature'; import { extractDeprecated, extractDescription, + extractJoinedRawExamples, extractModuleFieldName, extractModuleName, selectApiMethodSignatures, @@ -41,7 +43,7 @@ async function processModule( const moduleName = extractModuleName(module); console.log(`Processing Module ${moduleName}`); const moduleFieldName = extractModuleFieldName(module); - const { comment, deprecated } = analyzeModule(module); + const { comment, deprecated, examples } = analyzeModule(module); const methods = await processModuleMethods( module, `faker.${moduleFieldName}.` @@ -51,6 +53,7 @@ async function processModule( moduleName, moduleFieldName, comment, + examples, deprecated, methods ); @@ -65,10 +68,15 @@ async function processModule( export function analyzeModule(module: DeclarationReflection): { comment: string; deprecated: string | undefined; + examples: string | undefined; } { + const examplesRaw = extractJoinedRawExamples(module); + const examples = examplesRaw ? codeToHtml(examplesRaw) : undefined; + return { comment: adjustUrls(extractDescription(module)), deprecated: extractDeprecated(module), + examples, }; } -- cgit v1.2.3