Skip to content

Commit

Permalink
feat(core): exposed formatting with prettier options
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Nov 27, 2024
1 parent a667e80 commit e2a3467
Show file tree
Hide file tree
Showing 31 changed files with 439 additions and 217 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-cheetahs-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-markdown': minor
---

- Exposed formatting with prettier options (--formatWithPrettier and --prettierConfigFile).
2 changes: 2 additions & 0 deletions docs/pages/docs/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Options that are used to configure how the output is structured and displayed.

Options that are used for general configuration and utility purposes.

- [--formatWithPrettier](./options/utility-options.mdx#--formatwithprettier)
- [--prettierConfigFile](./options/utility-options.mdx#--prettierconfigfile)
- [--sanitizeComments](./options/utility-options.mdx#--sanitizecomments)
- [--publicPath](./options/utility-options.mdx#--publicpath)
- [--anchorPrefix](./options/utility-options.mdx#--anchorprefix)
Expand Down
43 changes: 43 additions & 0 deletions docs/pages/docs/options/utility-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@ import { Callout, FileTree } from "nextra/components";

Options that are used for general configuration and utility purposes.

## --formatWithPrettier

<Callout emoji="💡">Apply additional output formatting with Prettier.</Callout>

> Accepts a boolean value. Defaults to `false`.
`typedoc-plugin-markdown` plugin generates well-formatted code, however, integrating the popular formatting package [Prettier](https://prettier.io/) can provide additional enhancements, such as:

- Formats code inside fenced blocks using the respective Prettier configuration for that language.
- Aligns markdown table cells.
- Removes unnecessary escape characters.
- Wraps long lines of text to fit within a configurable line width.

Please note that Prettier is not a dependency of this plugin and must be installed in your project for this option to work.

If Prettier is not already installed please `npm i prettier --save-dev` to use this option.

```json filename="typedoc.json"
{
"formatWithPrettier": false
}
```

## --prettierConfigFile

<Callout emoji="💡">
Specify a custom Prettier configuration file location.
</Callout>

> Defaults to `"undefined"`.
By default Prettier uses the options resolved from a discovered Prettier [configuration file](https://prettier.io/docs/en/configuration.html).

Use this option to specify a separate Prettier configuration file in a custom location.

Please note this option is only applicable when `formatWithPrettier` is set to `true`.

```json filename="typedoc.json"
{
"prettierConfigFile": "./path/to/.prettierrc.json"
}
```

## --sanitizeComments

<Callout emoji="💡">Sanitize HTML and JSX inside JsDoc comments.</Callout>
Expand Down
20 changes: 0 additions & 20 deletions docs/pages/plugins/remark/useful-plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@

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

## unified-prettier

https://github.com/remcohaszing/unified-prettier

Improving code formatting by parsing with [Prettier](https://prettier.io/):

- Produces a consistent format.
- Removes unnecessary escape characters.
- Formats code blocks inside comment fenced blocks.

```sh npm2yarn
npm install unified-prettier --save-dev
```

```json filename="typedoc.json"
{
"remarkPlugins": ["unified-prettier"]
}
```

## remark-toc

https://github.com/remarkjs/remark-toc
Expand Down
116 changes: 50 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"tsx": "^4.19.2",
"typedoc": "^0.27.0-beta.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.15.0",
"unified-prettier": "^2.0.1"
"typescript-eslint": "^8.16.0"
}
}
2 changes: 2 additions & 0 deletions packages/typedoc-plugin-markdown/src/_typedoc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ declare module 'typedoc' {
expandParameters: boolean;
fileExtension: string;
flattenOutputFiles: boolean;
formatWithPrettier: boolean;
hideBreadcrumbs: boolean;
hideGroupHeadings: boolean;
hidePageHeader: boolean;
Expand All @@ -38,6 +39,7 @@ declare module 'typedoc' {
outputFileStrategy: 'members' | 'modules';
parametersFormat: 'list' | 'table' | 'htmlTable';
preserveAnchorCasing: boolean;
prettierConfigFile: string;
propertiesFormat: 'list' | 'table' | 'htmlTable';
propertyMembersFormat: 'list' | 'table' | 'htmlTable';
publicPath: string;
Expand Down
36 changes: 36 additions & 0 deletions packages/typedoc-plugin-markdown/src/options/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,42 @@ export const tableColumnSettings: Partial<DeclarationOption> = {
},
};

/**
* `typedoc-plugin-markdown` plugin generates well-formatted code, however, integrating the popular formatting package [Prettier](https://prettier.io/) can provide additional enhancements, such as:
*
* - Formats code inside fenced blocks using the respective Prettier configuration for that language.
* - Aligns markdown table cells.
* - Removes unnecessary escape characters.
* - Wraps long lines of text to fit within a configurable line width.
*
* Please note that Prettier is not a dependency of this plugin and must be installed in your project for this option to work.
*
* If Prettier is not already installed please `npm i prettier --save-dev` to use this option.
*
* @category Utility
*/
export const formatWithPrettier: Partial<DeclarationOption> = {
help: 'Apply additional output formatting with Prettier.',
type: ParameterType.Boolean,
defaultValue: false,
};

/**
* By default Prettier uses the options resolved from a discovered Prettier [configuration file](https://prettier.io/docs/en/configuration.html).
*
* Use this option to specify a separate Prettier configuration file in a custom location.
*
* Please note this option is only applicable when `formatWithPrettier` is set to `true`.
*
* @example "./path/to/.prettierrc.json"
*
* @category Utility
*/
export const prettierConfigFile: Partial<DeclarationOption> = {
help: 'Specify a custom Prettier configuration file location.',
type: ParameterType.Path,
};

/**
* *Please note this options does not affect the rendering of inline code or code blocks (using single/triple backticks).*
*
Expand Down
Loading

0 comments on commit e2a3467

Please sign in to comment.