Skip to content

Commit

Permalink
fix(frontmatter): prevent line wrapping as default in yaml.stringify(…
Browse files Browse the repository at this point in the history
…) options
  • Loading branch information
tgreyuk committed Feb 15, 2025
1 parent c50eb66 commit 42f9a60
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-dolls-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-frontmatter': patch
---

- Prevent line wrapping as default in yaml.stringify() options (#771).
5 changes: 4 additions & 1 deletion docs/pages/plugins/frontmatter/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ the `yaml.stringify` method from the [YAML](https://eemeli.org/yaml/#yaml) libra
For available options, see
[YAML ToString Options](https://eemeli.org/yaml/#tostring-options).

Please note that `{ lineWidth: 0 }` is set by default to prevent invalid wrapping.

```json filename="typedoc.json"
{
"yamlStringifyOptions": {
"lineWidth": 0
"defaultStringType": "QUOTE_SINGLE",
"defaultKeyType": "PLAIN"
}
}
```
2 changes: 1 addition & 1 deletion packages/typedoc-plugin-frontmatter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function load(app: MarkdownApplication) {
page.contents = page?.contents
?.replace(
/^/,
`---\n${yaml.stringify(page.frontmatter, yamlStringifyOptions)}---\n\n`,
`---\n${yaml.stringify(page.frontmatter, { ...yamlStringifyOptions, lineWidth: 0 })}---\n\n`,
)
.replace(/[\r\n]{3,}/g, '\n\n');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export const frontmatterNamingConvention: Partial<DeclarationOption> = {
* For available options, see
* [YAML ToString Options](https://eemeli.org/yaml/#tostring-options).
*
* @example { "lineWidth": 0 }
* Please note that `{ lineWidth: 0 }` is set by default to prevent invalid wrapping.
*
* @example {"defaultStringType": "QUOTE_SINGLE", "defaultKeyType": "PLAIN"}
*/
export const yamlStringifyOptions: Partial<DeclarationOption> = {
help: 'Options to pass into `yaml.stringify()`.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

exports[`Options: YAML should accept yaml stringify options 1`] = `
"---
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
isTrue: yes
veryLong: 'This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.'
---
# typedoc-plugin-frontmatter
Expand Down Expand Up @@ -31,8 +32,7 @@ exports[`Options: YAML should prepend frontmatter for readme page 1`] = `
"---
title: typedoc-plugin-frontmatter
layout: blog
veryLong: This is a long string that would normally wrap over multiple lines
when the text exceeds a certain length.
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
navOrder: 1
hide: true
onReadme: true
Expand All @@ -46,8 +46,7 @@ exports[`Options: YAML should prepend frontmatter to index page 1`] = `
"---
title: typedoc-plugin-frontmatter
layout: blog
veryLong: This is a long string that would normally wrap over multiple lines
when the text exceeds a certain length.
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
navOrder: 1
hide: true
onIndex: true
Expand All @@ -65,8 +64,7 @@ exports[`Options: YAML should prepend frontmatter with preserved tags 1`] = `
"---
title: SomeInterface
layout: blog
veryLong: This is a long string that would normally wrap over multiple lines
when the text exceeds a certain length.
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
navOrder: 1
hide: true
tagOne: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ module.exports = {
hidePageHeader: true,
hideBreadcrumbs: true,
frontmatterGlobals: {
isTrue: true,
veryLong:
'This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.',
},
yamlStringifyOptions: {
lineWidth: 0,
trueStr: 'yes',
defaultStringType: 'QUOTE_SINGLE',
defaultKeyType: 'PLAIN',
},
disableSources: true,
};

0 comments on commit 42f9a60

Please sign in to comment.