Skip to content

Commit 3e27a1b

Browse files
committed
feat(core): exposed formatting with prettier options
1 parent ae70112 commit 3e27a1b

File tree

21 files changed

+358
-185
lines changed

21 files changed

+358
-185
lines changed

.changeset/chatty-cheetahs-love.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'typedoc-plugin-markdown': minor
3+
---
4+
5+
- Exposed formatting with prettier options (--formatWithPrettier and --prettierConfigFile).

docs/pages/docs/options.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Options that are used to configure how the output is structured and displayed.
4747

4848
Options that are used for general configuration and utility purposes.
4949

50+
- [--formatWithPrettier](./options/utility-options.mdx#--formatwithprettier)
51+
- [--prettierConfigFile](./options/utility-options.mdx#--prettierconfigfile)
5052
- [--sanitizeComments](./options/utility-options.mdx#--sanitizecomments)
5153
- [--publicPath](./options/utility-options.mdx#--publicpath)
5254
- [--anchorPrefix](./options/utility-options.mdx#--anchorprefix)

docs/pages/docs/options/utility-options.mdx

+43
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,49 @@ import { Callout, FileTree } from "nextra/components";
44

55
Options that are used for general configuration and utility purposes.
66

7+
## --formatWithPrettier
8+
9+
<Callout emoji="💡">Apply additional output formatting with Prettier.</Callout>
10+
11+
> Accepts a boolean value. Defaults to `false`.
12+
13+
`typedoc-plugin-markdown` plugin generates well-formatted code, however, integrating the popular formatting package [Prettier](https://prettier.io/) can provide additional enhancements, such as:
14+
15+
- Formats code inside fenced blocks using the respective Prettier configuration for that language.
16+
- Aligns markdown table cells.
17+
- Removes unnecessary escape characters.
18+
- Wraps long lines of text to fit within a configurable line width.
19+
20+
Please note that Prettier is not a dependency of this plugin and must be installed in your project for this option to work.
21+
22+
If Prettier is not already installed please `npm i prettier --save-dev` to use this option.
23+
24+
```json filename="typedoc.json"
25+
{
26+
"formatWithPrettier": false
27+
}
28+
```
29+
30+
## --prettierConfigFile
31+
32+
<Callout emoji="💡">
33+
Specify a custom Prettier configuration file location.
34+
</Callout>
35+
36+
> Defaults to `"undefined"`.
37+
38+
By default Prettier uses the options resolved from a discovered Prettier [configuration file](https://prettier.io/docs/en/configuration.html).
39+
40+
Use this option to specify a separate Prettier configuration file in a custom location.
41+
42+
Please note this option is only applicable when `formatWithPrettier` is set to `true`.
43+
44+
```json filename="typedoc.json"
45+
{
46+
"prettierConfigFile": "./path/to/.prettierrc.json"
47+
}
48+
```
49+
750
## --sanitizeComments
851

952
<Callout emoji="💡">Sanitize HTML and JSX inside JsDoc comments.</Callout>

docs/pages/plugins/remark/useful-plugins.mdx

-20
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,6 @@
22

33
Here are some [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md) that might be useful.
44

5-
## unified-prettier
6-
7-
https://github.com/remcohaszing/unified-prettier
8-
9-
Improving code formatting by parsing with [Prettier](https://prettier.io/):
10-
11-
- Produces a consistent format.
12-
- Removes unnecessary escape characters.
13-
- Formats code blocks inside comment fenced blocks.
14-
15-
```sh npm2yarn
16-
npm install unified-prettier --save-dev
17-
```
18-
19-
```json filename="typedoc.json"
20-
{
21-
"remarkPlugins": ["unified-prettier"]
22-
}
23-
```
24-
255
## remark-toc
266

277
https://github.com/remarkjs/remark-toc

package-lock.json

+50-66
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"tsx": "^4.19.2",
5353
"typedoc": "^0.27.0-beta.2",
5454
"typescript": "^5.7.2",
55-
"typescript-eslint": "^8.15.0",
56-
"unified-prettier": "^2.0.1"
55+
"typescript-eslint": "^8.16.0"
5756
}
5857
}

packages/typedoc-plugin-markdown/src/_typedoc.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ declare module 'typedoc' {
1414
expandParameters: boolean;
1515
fileExtension: string;
1616
flattenOutputFiles: boolean;
17+
formatWithPrettier: boolean;
1718
hideBreadcrumbs: boolean;
1819
hideGroupHeadings: boolean;
1920
hidePageHeader: boolean;
@@ -38,6 +39,7 @@ declare module 'typedoc' {
3839
outputFileStrategy: 'members' | 'modules';
3940
parametersFormat: 'list' | 'table' | 'htmlTable';
4041
preserveAnchorCasing: boolean;
42+
prettierConfigFile: string;
4143
propertiesFormat: 'list' | 'table' | 'htmlTable';
4244
propertyMembersFormat: 'list' | 'table' | 'htmlTable';
4345
publicPath: string;

packages/typedoc-plugin-markdown/src/options/declarations.ts

+36
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,42 @@ export const tableColumnSettings: Partial<DeclarationOption> = {
551551
},
552552
};
553553

554+
/**
555+
* `typedoc-plugin-markdown` plugin generates well-formatted code, however, integrating the popular formatting package [Prettier](https://prettier.io/) can provide additional enhancements, such as:
556+
*
557+
* - Formats code inside fenced blocks using the respective Prettier configuration for that language.
558+
* - Aligns markdown table cells.
559+
* - Removes unnecessary escape characters.
560+
* - Wraps long lines of text to fit within a configurable line width.
561+
*
562+
* Please note that Prettier is not a dependency of this plugin and must be installed in your project for this option to work.
563+
*
564+
* If Prettier is not already installed please `npm i prettier --save-dev` to use this option.
565+
*
566+
* @category Utility
567+
*/
568+
export const formatWithPrettier: Partial<DeclarationOption> = {
569+
help: 'Apply additional output formatting with Prettier.',
570+
type: ParameterType.Boolean,
571+
defaultValue: false,
572+
};
573+
574+
/**
575+
* By default Prettier uses the options resolved from a discovered Prettier [configuration file](https://prettier.io/docs/en/configuration.html).
576+
*
577+
* Use this option to specify a separate Prettier configuration file in a custom location.
578+
*
579+
* Please note this option is only applicable when `formatWithPrettier` is set to `true`.
580+
*
581+
* @example "./path/to/.prettierrc.json"
582+
*
583+
* @category Utility
584+
*/
585+
export const prettierConfigFile: Partial<DeclarationOption> = {
586+
help: 'Specify a custom Prettier configuration file location.',
587+
type: ParameterType.Path,
588+
};
589+
554590
/**
555591
* *Please note this options does not affect the rendering of inline code or code blocks (using single/triple backticks).*
556592
*

0 commit comments

Comments
 (0)