Skip to content

Commit

Permalink
Add typePrintWidth option
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Sep 7, 2024
1 parent 3ac6578 commit 4f56858
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 9 additions & 0 deletions site/options/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/lib/internationalization/locales/en.cts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/output/themes/default/partials/type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface TypeDocOptionMap {
lightHighlightTheme: ShikiTheme;
darkHighlightTheme: ShikiTheme;
highlightLanguages: string[];
typePrintWidth: number;
customCss: string;
markdownItOptions: ManuallyValidatedOption<Record<string, unknown>>;
/**
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
}
},
});
options.addDeclaration({
name: "typePrintWidth",
help: (i18n) => i18n.help_typePrintWidth(),
type: ParameterType.Number,
defaultValue: 80,
});

options.addDeclaration({
name: "customCss",
Expand Down

0 comments on commit 4f56858

Please sign in to comment.