Skip to content

Commit b6a4735

Browse files
authored
chore(repo): Modify Typedoc union type output (#5403)
1 parent 457ac5a commit b6a4735

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

.typedoc/custom-theme.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,28 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
345345

346346
return md.join('\n\n');
347347
},
348+
/**
349+
* Copied from default theme / source code. This modifies the output of union types by wrapping everything in a single `<code>foo | bar</code>` tag instead of doing `<code>foo</code>` | `<code>bar</code>`
350+
* https://github.com/typedoc2md/typedoc-plugin-markdown/blob/5d7c3c7fb816b6b009f3425cf284c95400f53929/packages/typedoc-plugin-markdown/src/theme/context/partials/type.union.ts
351+
* @param {import('typedoc').UnionType} model
352+
*/
353+
unionType: model => {
354+
const useCodeBlocks = this.options.getValue('useCodeBlocks');
355+
const typesOut = model.types.map(unionType => {
356+
// So, .someType adds the backticks to the string and we don't want to deal with modifying that partial. So just remove any backticks in the next step again :shrug:
357+
const defaultResult = this.partials.someType(unionType, { forceCollapse: true });
358+
359+
// Remove any backticks
360+
return defaultResult.replace(/`/g, '');
361+
});
362+
363+
const shouldFormat = useCodeBlocks && (typesOut?.join('').length > 70 || typesOut?.join('').includes('\n'));
364+
365+
const md = typesOut.join(shouldFormat ? `\n \\| ` : ` \\| `);
366+
const result = shouldFormat ? `\n \\| ` + md : md;
367+
368+
return `<code>${result}</code>`;
369+
},
348370
};
349371
}
350372
}

0 commit comments

Comments
 (0)