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 1 commit
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
8 changes: 6 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,18 @@ import json2md from 'json2md';
*/
import { generateMarkdownPropsJson } from './props.mjs';

function normalizeTrailingNewline( str ) {
return str?.length ? str.replace( /\n*$/, '\n' ) : undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure I understand, this aims to result in having exactly one newline, even if the description doesn't come with a newline, right? Even in the case of an empty description string, which will also result in just a newline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I hope this captures the intent better: e5e4a65

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it does 👍 Also thanks for using trim() instead of length, that basically makes it impossible to break with an arbitrary space or tab.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to ship 🚀

}

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 +30,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