Skip to content

Commit fc43ce9

Browse files
committed
feat(frontmatter): expose "yamlStringifyOptions" option
1 parent ac664f7 commit fc43ce9

File tree

14 files changed

+124
-13
lines changed

14 files changed

+124
-13
lines changed

.changeset/config.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"ignore": [
1414
"@devtools/*",
1515
"typedoc-github-wiki-theme",
16-
"typedoc-gitlab-wiki-theme",
17-
"typedoc-plugin-frontmatter"
16+
"typedoc-gitlab-wiki-theme"
1817
]
1918
}

.changeset/curvy-radios-wash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'typedoc-plugin-frontmatter': minor
3+
---
4+
5+
- Expose "yamlStringifyOptions" option (#771).

docs/pages/plugins/frontmatter/options.mdx

+24
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ description: A description that will be added to frontmatter.
9999

100100
> Accepts a boolean value. Defaults to `false`.
101101
102+
By default tags defined in `frontmatterCommentTags` are removed from final output.
103+
104+
Use this option to preserve the tags in the output.
105+
102106
```json filename="typedoc.json"
103107
{
104108
"preserveFrontmatterCommentTags": false
@@ -122,3 +126,23 @@ This option can configure the output style of frontmatter variables when written
122126
"frontmatterNamingConvention": "camelCase"
123127
}
124128
```
129+
130+
## yamlStringifyOptions
131+
132+
<Callout emoji="💡">Options to pass into `yaml.stringify()`.</Callout>
133+
134+
> Accepts a key/value object.
135+
136+
Provides additional options to control how YAML is internally serialized using
137+
the `yaml.stringify` method from the [YAML](https://eemeli.org/yaml/#yaml) library.
138+
139+
For available options, see
140+
[YAML ToString Options](https://eemeli.org/yaml/#tostring-options).
141+
142+
```json filename="typedoc.json"
143+
{
144+
"yamlStringifyOptions": {
145+
"lineWidth": 0
146+
}
147+
}
148+
```

package-lock.json

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

packages/typedoc-plugin-frontmatter/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"homepage": "https://typedoc-plugin-markdown.org/plugins/frontmatter",
3333
"dependencies": {
34-
"yaml": "^2.3.4"
34+
"yaml": "^2.7.0"
3535
},
3636
"peerDependencies": {
3737
"typedoc-plugin-markdown": ">=4.4.2"

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

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY.
22
import { ManuallyValidatedOption } from 'typedoc';
3+
import { ToStringOptions } from 'yaml';
4+
35
declare module 'typedoc' {
46
export interface TypeDocOptionMap {
57
frontmatterCommentTags: string[];
@@ -8,5 +10,6 @@ declare module 'typedoc' {
810
indexFrontmatter: ManuallyValidatedOption<Record<string, any>>;
911
preserveFrontmatterCommentTags: boolean;
1012
readmeFrontmatter: ManuallyValidatedOption<Record<string, any>>;
13+
yamlStringifyOptions: ManuallyValidatedOption<ToStringOptions>;
1114
}
1215
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ export function load(app: MarkdownApplication) {
6060
MarkdownPageEvent.END,
6161
(page: MarkdownPageEvent<ProjectReflection | DeclarationReflection>) => {
6262
if (page.frontmatter && Object.keys(page.frontmatter)?.length) {
63+
const yamlStringifyOptions = app.options.getValue(
64+
'yamlStringifyOptions',
65+
);
6366
page.contents = page?.contents
64-
?.replace(/^/, `---\n${yaml.stringify(page.frontmatter)}---\n\n`)
67+
?.replace(
68+
/^/,
69+
`---\n${yaml.stringify(page.frontmatter, yamlStringifyOptions)}---\n\n`,
70+
)
6571
.replace(/[\r\n]{3,}/g, '\n\n');
6672
}
6773
},

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

+20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export const frontmatterCommentTags: Partial<DeclarationOption> = {
9090
type: ParameterType.Array,
9191
};
9292

93+
/**
94+
* By default tags defined in `frontmatterCommentTags` are removed from final output.
95+
*
96+
* Use this option to preserve the tags in the output.
97+
*/
9398
export const preserveFrontmatterCommentTags: Partial<DeclarationOption> = {
9499
help: 'Preserve tags defined in frontmatter block tags in output.',
95100
type: ParameterType.Boolean,
@@ -107,3 +112,18 @@ export const frontmatterNamingConvention: Partial<DeclarationOption> = {
107112
map: FrontmatterNamingConvention,
108113
defaultValue: FrontmatterNamingConvention.CamelCase,
109114
};
115+
116+
/**
117+
* Provides additional options to control how YAML is internally serialized using
118+
* the `yaml.stringify` method from the [YAML](https://eemeli.org/yaml/#yaml) library.
119+
*
120+
* For available options, see
121+
* [YAML ToString Options](https://eemeli.org/yaml/#tostring-options).
122+
*
123+
* @example { "lineWidth": 0 }
124+
*/
125+
export const yamlStringifyOptions: Partial<DeclarationOption> = {
126+
help: 'Options to pass into `yaml.stringify()`.',
127+
type: ParameterType.Object,
128+
defaultValue: {},
129+
};

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

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY
33
*/
4+
import { ToStringOptions } from 'yaml';
45
/**
56
* Describes the options declared by the plugin.
67
*/
@@ -34,4 +35,9 @@ export interface PluginOptions {
3435
* Specify static variables to be added to the readme page only.
3536
*/
3637
readmeFrontmatter: Record<string, any>;
38+
39+
/**
40+
* Options to pass into `yaml.stringify()`.
41+
*/
42+
yamlStringifyOptions: ToStringOptions;
3743
}

packages/typedoc-plugin-frontmatter/test/__scripts__/prepare.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fs.removeSync(`./test/out`);
1212
const fixtures = [
1313
{ options: 'typedoc-options.cjs', outDir: 'options' },
1414
{ options: 'typedoc-options-2.cjs', outDir: 'options-2' },
15+
{ options: 'typedoc-options-3.cjs', outDir: 'options-3' },
1516
{ options: 'typedoc-base.json', outDir: 'no-data' },
1617
];
1718

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

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Options: YAML should accept yaml stringify options 1`] = `
4+
"---
5+
veryLong: This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.
6+
---
7+
8+
# typedoc-plugin-frontmatter
9+
10+
## Interfaces
11+
12+
- [SomeInterface](interfaces/SomeInterface.md)
13+
"
14+
`;
15+
316
exports[`Options: YAML should prepend frontmatter 1`] = `
417
"---
518
title: SomeInterface
@@ -18,6 +31,8 @@ exports[`Options: YAML should prepend frontmatter for readme page 1`] = `
1831
"---
1932
title: typedoc-plugin-frontmatter
2033
layout: blog
34+
veryLong: This is a long string that would normally wrap over multiple lines
35+
when the text exceeds a certain length.
2136
navOrder: 1
2237
hide: true
2338
onReadme: true
@@ -31,6 +46,8 @@ exports[`Options: YAML should prepend frontmatter to index page 1`] = `
3146
"---
3247
title: typedoc-plugin-frontmatter
3348
layout: blog
49+
veryLong: This is a long string that would normally wrap over multiple lines
50+
when the text exceeds a certain length.
3451
navOrder: 1
3552
hide: true
3653
onIndex: true
@@ -48,6 +65,8 @@ exports[`Options: YAML should prepend frontmatter with preserved tags 1`] = `
4865
"---
4966
title: SomeInterface
5067
layout: blog
68+
veryLong: This is a long string that would normally wrap over multiple lines
69+
when the text exceeds a certain length.
5170
navOrder: 1
5271
hide: true
5372
tagOne: 0

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

+7
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,12 @@ describe(`Options:`, () => {
3636
.toString();
3737
expect(pageContent).toMatchSnapshot();
3838
});
39+
40+
test(`should accept yaml stringify options`, async () => {
41+
const pageContent = fs
42+
.readFileSync(path.join(__dirname, '../out/options-3/README.md'))
43+
.toString();
44+
expect(pageContent).toMatchSnapshot();
45+
});
3946
});
4047
});

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

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module.exports = {
2222
},
2323
frontmatterGlobals: {
2424
layout: 'blog',
25+
veryLong:
26+
'This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.',
2527
navOrder: 1,
2628
hide: true,
2729
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @ts-check
2+
3+
/** @type {import('typedoc').TypeDocOptions & import('typedoc-plugin-markdown').PluginOptions & import('typedoc-plugin-frontmatter').PluginOptions} */
4+
module.exports = {
5+
entryPoints: ['./stubs.ts'],
6+
tsconfig: '../tsconfig.test.json',
7+
readme: 'none',
8+
plugin: ['typedoc-plugin-markdown', 'typedoc-plugin-frontmatter'],
9+
hidePageHeader: true,
10+
hideBreadcrumbs: true,
11+
frontmatterGlobals: {
12+
veryLong:
13+
'This is a long string that would normally wrap over multiple lines when the text exceeds a certain length.',
14+
},
15+
yamlStringifyOptions: {
16+
lineWidth: 0,
17+
},
18+
disableSources: true,
19+
};

0 commit comments

Comments
 (0)