Skip to content

Commit

Permalink
Components: Normalize newlines in auto-generated READMEs (#68208)
Browse files Browse the repository at this point in the history
* Components: Normalize newlines

* Clarify helper function

Co-authored-by: mirka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent d9f18e5 commit ca24cce
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 2 deletions.
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
1 change: 1 addition & 0 deletions packages/components/src/alignment-matrix-control/README.md
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

1 comment on commit ca24cce

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in ca24cce.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12439613186
📝 Reported issues:

Please sign in to comment.