From 4f5685861c72b6d54e2d09d330ba22f78d5bce75 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 7 Sep 2024 17:10:28 -0600 Subject: [PATCH] Add typePrintWidth option --- CHANGELOG.md | 2 +- site/options/output.md | 9 +++++++++ src/lib/internationalization/locales/en.cts | 2 ++ .../themes/default/partials/member.declaration.tsx | 2 +- .../themes/default/partials/member.signature.title.tsx | 2 +- .../output/themes/default/partials/reflectionPreview.tsx | 2 +- src/lib/output/themes/default/partials/type.tsx | 2 +- src/lib/utils/options/declaration.ts | 1 + src/lib/utils/options/sources/typedoc.ts | 6 ++++++ 9 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b700c3d..86a82de81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,10 +26,10 @@ title: Changelog TODO: -- Add an option for controlling print width. - Write docs for `@expand` - Docs for `@summary` - Write docs for `@import` +- Write docs for `@class` - Write docs for `@include` and `@includeCode` - https://github.com/ebullient/markdown-it-obsidian-callouts plugin - Validate anchors within relative linked paths? diff --git a/site/options/output.md b/site/options/output.md index 95b26e571..442ec3353 100644 --- a/site/options/output.md +++ b/site/options/output.md @@ -97,6 +97,15 @@ loads the following languages. } ``` +## typePrintWidth + +Specifies the width at which to wrap code when rendering types, defaults to 80. +Changing this is not advised without tweaks to the theme in use. + +```bash +typedoc --typePrintWidth 120 +``` + ## customCss ```bash diff --git a/src/lib/internationalization/locales/en.cts b/src/lib/internationalization/locales/en.cts index 23b6a723e..5e70261c9 100644 --- a/src/lib/internationalization/locales/en.cts +++ b/src/lib/internationalization/locales/en.cts @@ -229,6 +229,8 @@ export = { help_darkHighlightTheme: "Specify the code highlighting theme in dark mode", help_highlightLanguages: "Specify the languages which will be loaded to highlight code when rendering", + help_typePrintWidth: + "Width at which to wrap code to a new line when rendering a type", help_customCss: "Path to a custom CSS file to for the theme to import", help_markdownItOptions: "Specify the options passed to markdown-it, the Markdown parser used by TypeDoc", diff --git a/src/lib/output/themes/default/partials/member.declaration.tsx b/src/lib/output/themes/default/partials/member.declaration.tsx index 502fd406f..b9c9868cf 100644 --- a/src/lib/output/themes/default/partials/member.declaration.tsx +++ b/src/lib/output/themes/default/partials/member.declaration.tsx @@ -8,7 +8,7 @@ export function memberDeclaration(context: DefaultThemeRenderContext, props: Dec const builder = new FormattedCodeBuilder(context.urlTo); const content: FormatterNode[] = []; builder.member(content, props, { topLevelLinks: false }); - const generator = new FormattedCodeGenerator(); + const generator = new FormattedCodeGenerator(context.options.getValue("typePrintWidth")); generator.node({ type: "nodes", content }, Wrap.Detect); return ( diff --git a/src/lib/output/themes/default/partials/member.signature.title.tsx b/src/lib/output/themes/default/partials/member.signature.title.tsx index dd1421f8d..002369feb 100644 --- a/src/lib/output/themes/default/partials/member.signature.title.tsx +++ b/src/lib/output/themes/default/partials/member.signature.title.tsx @@ -9,7 +9,7 @@ export function memberSignatureTitle( ) { const builder = new FormattedCodeBuilder(context.urlTo); const tree = builder.signature(props, options); - const generator = new FormattedCodeGenerator(); + const generator = new FormattedCodeGenerator(context.options.getValue("typePrintWidth")); generator.node(tree, Wrap.Detect); return generator.toElement(); } diff --git a/src/lib/output/themes/default/partials/reflectionPreview.tsx b/src/lib/output/themes/default/partials/reflectionPreview.tsx index 1a927d7c4..abcbc7ffe 100644 --- a/src/lib/output/themes/default/partials/reflectionPreview.tsx +++ b/src/lib/output/themes/default/partials/reflectionPreview.tsx @@ -12,7 +12,7 @@ export function reflectionPreview(context: DefaultThemeRenderContext, props: Ref if (props.kindOf(ReflectionKind.Interface) && props.children) { const builder = new FormattedCodeBuilder(context.urlTo); const tree = builder.interface(props); - const generator = new FormattedCodeGenerator(); + const generator = new FormattedCodeGenerator(context.options.getValue("typePrintWidth")); generator.forceWrap(builder.forceWrap); // Ensure elements are added to new lines. generator.node(tree, Wrap.Enable); diff --git a/src/lib/output/themes/default/partials/type.tsx b/src/lib/output/themes/default/partials/type.tsx index 073162f5a..3017d7381 100644 --- a/src/lib/output/themes/default/partials/type.tsx +++ b/src/lib/output/themes/default/partials/type.tsx @@ -9,7 +9,7 @@ export function type( ) { const builder = new FormattedCodeBuilder(context.urlTo); const tree = builder.type(type, TypeContext.none, options); - const generator = new FormattedCodeGenerator(); + const generator = new FormattedCodeGenerator(context.options.getValue("typePrintWidth")); generator.node(tree, Wrap.Detect); return generator.toElement(); } diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index e3f306917..8bba99423 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -136,6 +136,7 @@ export interface TypeDocOptionMap { lightHighlightTheme: ShikiTheme; darkHighlightTheme: ShikiTheme; highlightLanguages: string[]; + typePrintWidth: number; customCss: string; markdownItOptions: ManuallyValidatedOption>; /** diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index 8c2ab4ff4..f0df02b9f 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -333,6 +333,12 @@ export function addTypeDocOptions(options: Pick) { } }, }); + options.addDeclaration({ + name: "typePrintWidth", + help: (i18n) => i18n.help_typePrintWidth(), + type: ParameterType.Number, + defaultValue: 80, + }); options.addDeclaration({ name: "customCss",