diff --git a/src/formatter/format.ts b/src/formatter/format.ts index 941f9f0..7761cc5 100644 --- a/src/formatter/format.ts +++ b/src/formatter/format.ts @@ -5,6 +5,8 @@ import * as md from './markdown'; import { defaultNameTransform } from './name-transform'; import type { NameTransformFn } from './types'; +const MAX_VALUES = 20; + export function formatModelsAsMarkdown( models: NamedModel[], options: FormatterOptions @@ -97,11 +99,20 @@ function formatModel(model: Model, transformName: NameTransformFn): string { ) ); case 'enum': + const enumList = md.list.unordered( + model.values.map(value => md.code.inline(`'${value}'`)) + ); return md.paragraphs( md.italic('Enum string, one of the following possible values:'), - md.list.unordered( - model.values.map(value => md.code.inline(`'${value}'`)) - ) + model.values.length > MAX_VALUES + ? md.details( + md.italic( + `Expand for full list of ${model.values.length} values`, + 'html' + ), + enumList + ) + : enumList ); case 'native-enum': return md.paragraphs( @@ -373,7 +384,11 @@ function formatModelInline( ); case 'enum': return md.code.inline( - model.values.map(value => `'${value}'`).join(' | ') + model.values + .slice(0, MAX_VALUES) + .map(value => `'${value}'`) + .concat(model.values.length > MAX_VALUES ? ['...'] : []) + .join(' | ') ); case 'native-enum': return ( diff --git a/src/formatter/markdown.ts b/src/formatter/markdown.ts index 2a6c975..0db3cc8 100644 --- a/src/formatter/markdown.ts +++ b/src/formatter/markdown.ts @@ -17,9 +17,11 @@ export const paragraphs = (...texts: (string | null | undefined | false)[]) => export const heading = (level: 1 | 2 | 3 | 4 | 5 | 6, text: string) => `${'#'.repeat(level)} ${text}`; -export const bold = (text: string) => `**${text}**`; +export const bold = (text: string, lang: 'md' | 'html' = 'md') => + lang === 'html' ? `${text}` : `**${text}**`; -export const italic = (text: string) => `_${text}_`; +export const italic = (text: string, lang: 'md' | 'html' = 'md') => + lang === 'html' ? `${text}` : `_${text}_`; export const link = (href: string, text?: string) => `[${text ?? href}](${href})`; @@ -99,3 +101,11 @@ export const table = ( return lines(...rows.map(row => `| ${row.map(formatCell).join(' | ')} |`)); }; + +export const details = (summary: string, details: string) => + lines( + '
', + `${summary}`, + `\n${details}\n`.replace(/^\n{2,}/, '\n').replace(/\n{2,}$/, '\n'), + '
' + );