Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components: Normalize newlines in auto-generated READMEs #68208

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions bin/api-docs/gen-components-docs/markdown/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ import json2md from 'json2md';
*/
import { generateMarkdownPropsJson } from './props.mjs';

/**
* If the string is contentful, ensure that it ends with a single newline.
* Otherwise normalize to `undefined`.
*
* @param {string} [str]
*/
function normalizeTrailingNewline( str ) {
if ( ! str?.trim() ) {
return undefined;
}
return str.replace( /\n*$/, '\n' );
}

export function generateMarkdownDocs( { typeDocs, subcomponentTypeDocs } ) {
const mainDocsJson = [
{ h1: typeDocs.displayName },
'<!-- This file is generated automatically and cannot be edited directly. Make edits via TypeScript types and TSDocs. -->',
{
p: `<p class="callout callout-info">See the <a href="https://wordpress.github.io/gutenberg/?path=/docs/components-${ typeDocs.displayName.toLowerCase() }--docs">WordPress Storybook</a> for more detailed, interactive documentation.</p>`,
},
typeDocs.description,
normalizeTrailingNewline( typeDocs.description ),
...generateMarkdownPropsJson( typeDocs.props ),
];

Expand All @@ -26,7 +39,7 @@ export function generateMarkdownDocs( { typeDocs, subcomponentTypeDocs } ) {
{
h3: subcomponentTypeDoc.displayName,
},
subcomponentTypeDoc.description,
normalizeTrailingNewline( subcomponentTypeDoc.description ),
...generateMarkdownPropsJson( subcomponentTypeDoc.props, {
headingLevel: 4,
} ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Example = () => {
);
};
```

## Props

### `defaultValue`
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/angle-picker-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Example() {
);
}
```

## Props

### `as`
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/base-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const MyCustomTextareaControl = ({ children, ...baseProps }) => (
);
);
```

## Props

### `__nextHasNoMarginBottom`
Expand Down Expand Up @@ -113,6 +114,7 @@ const MyBaseControl = () => (
</BaseControl>
);
```

#### Props

##### `as`
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/box-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function Example() {
);
};
```

## Props

### `__next40pxDefaultSize`
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Mybutton = () => (
</Button>
);
```

## Props

### `__next40pxDefaultSize`
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/form-file-upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const MyFormFileUpload = () => (
</FormFileUpload>
);
```

## Props

### `__next40pxDefaultSize`
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/gradient-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const MyGradientPicker = () => {
);
};
```

## Props

### `__experimentalIsRenderedInSidebar`
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/icon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { wordpress } from '@wordpress/icons';

<Icon icon={ wordpress } />
```

## Props

### `icon`
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/tree-select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const MyTreeSelect = () => {
);
}
```

## Props

### `__next40pxDefaultSize`
Expand Down
Loading