Skip to content

Commit 42f9a60

Browse files
committed
fix(frontmatter): prevent line wrapping as default in yaml.stringify() options
1 parent c50eb66 commit 42f9a60

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

.changeset/empty-dolls-explain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'typedoc-plugin-frontmatter': patch
3+
---
4+
5+
- Prevent line wrapping as default in yaml.stringify() options (#771).

docs/pages/plugins/frontmatter/options.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ the `yaml.stringify` method from the [YAML](https://eemeli.org/yaml/#yaml) libra
139139
For available options, see
140140
[YAML ToString Options](https://eemeli.org/yaml/#tostring-options).
141141

142+
Please note that `{ lineWidth: 0 }` is set by default to prevent invalid wrapping.
143+
142144
```json filename="typedoc.json"
143145
{
144146
"yamlStringifyOptions": {
145-
"lineWidth": 0
147+
"defaultStringType": "QUOTE_SINGLE",
148+
"defaultKeyType": "PLAIN"
146149
}
147150
}
148151
```

packages/typedoc-plugin-frontmatter/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function load(app: MarkdownApplication) {
6666
page.contents = page?.contents
6767
?.replace(
6868
/^/,
69-
`---\n${yaml.stringify(page.frontmatter, yamlStringifyOptions)}---\n\n`,
69+
`---\n${yaml.stringify(page.frontmatter, { ...yamlStringifyOptions, lineWidth: 0 })}---\n\n`,
7070
)
7171
.replace(/[\r\n]{3,}/g, '\n\n');
7272
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ export const frontmatterNamingConvention: Partial<DeclarationOption> = {
120120
* For available options, see
121121
* [YAML ToString Options](https://eemeli.org/yaml/#tostring-options).
122122
*
123-
* @example { "lineWidth": 0 }
123+
* Please note that `{ lineWidth: 0 }` is set by default to prevent invalid wrapping.
124+
*
125+
* @example {"defaultStringType": "QUOTE_SINGLE", "defaultKeyType": "PLAIN"}
124126
*/
125127
export const yamlStringifyOptions: Partial<DeclarationOption> = {
126128
help: 'Options to pass into `yaml.stringify()`.',

packages/typedoc-plugin-frontmatter/test/specs/__snapshots__/options.spec.ts.snap

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
exports[`Options: YAML should accept yaml stringify options 1`] = `
44
"---
5-
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
5+
isTrue: yes
6+
veryLong: 'This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.'
67
---
78
89
# typedoc-plugin-frontmatter
@@ -31,8 +32,7 @@ exports[`Options: YAML should prepend frontmatter for readme page 1`] = `
3132
"---
3233
title: typedoc-plugin-frontmatter
3334
layout: blog
34-
veryLong: This is a long string that would normally wrap over multiple lines
35-
when the text exceeds a certain length.
35+
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
3636
navOrder: 1
3737
hide: true
3838
onReadme: true
@@ -46,8 +46,7 @@ exports[`Options: YAML should prepend frontmatter to index page 1`] = `
4646
"---
4747
title: typedoc-plugin-frontmatter
4848
layout: blog
49-
veryLong: This is a long string that would normally wrap over multiple lines
50-
when the text exceeds a certain length.
49+
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
5150
navOrder: 1
5251
hide: true
5352
onIndex: true
@@ -65,8 +64,7 @@ exports[`Options: YAML should prepend frontmatter with preserved tags 1`] = `
6564
"---
6665
title: SomeInterface
6766
layout: blog
68-
veryLong: This is a long string that would normally wrap over multiple lines
69-
when the text exceeds a certain length.
67+
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
7068
navOrder: 1
7169
hide: true
7270
tagOne: 0

packages/typedoc-plugin-frontmatter/test/typedoc-options-3.cjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ module.exports = {
99
hidePageHeader: true,
1010
hideBreadcrumbs: true,
1111
frontmatterGlobals: {
12+
isTrue: true,
1213
veryLong:
1314
'This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.',
1415
},
1516
yamlStringifyOptions: {
16-
lineWidth: 0,
17+
trueStr: 'yes',
18+
defaultStringType: 'QUOTE_SINGLE',
19+
defaultKeyType: 'PLAIN',
1720
},
1821
disableSources: true,
1922
};

0 commit comments

Comments
 (0)