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: Prevent broken lists in auto-generated readmes #68301

Merged
merged 3 commits into from
Dec 26, 2024

Conversation

mirka
Copy link
Member

@mirka mirka commented Dec 25, 2024

What?

Prevents broken lists (ul) in the auto-generated component READMEs, by inverting the order of the "prop data" ul and the prop description.

Why?

Because we can assume that a prop description will always start with a paragraph (not ul), flipping the order here should solve the "ambiguous run-on list" problem when the prop description ends with a list.

Before

### `myProp`

This is my prop description. The prop does three things:

- Foo
- Bar
- Baz

- Type: `string`
- Required: No

The ambiguously separated Markdown lists will render unreliably, depending on the HTML converter implementation.

After

### `myProp`

- Type: `string`
- Required: No

This is my prop description. The prop does three things:

- Foo
- Bar
- Baz

Now the lists are clearly separated.

Testing Instructions

The READMEs re-generated by npm run docs:components do not include ambiguous lists, even when a prop description ends with a list.

@mirka mirka added [Type] Developer Documentation Documentation for developers [Package] Components /packages/components labels Dec 25, 2024
@mirka mirka self-assigned this Dec 25, 2024
Copy link

github-actions bot commented Dec 25, 2024

Flaky tests detected in 4690b1d.
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/12503550187
📝 Reported issues:

Comment on lines +17 to +19
json2md.converters.md = ( input ) => {
return input?.trim() || '';
};
Copy link
Member Author

Choose a reason for hiding this comment

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

I realized you can add custom converters like this, which makes things more simpler and readable overall. When you use a converter, json2md adds a trailing newline automatically.

The removal of redundant newlines is moved to the end of this file, which will clean the entire output.

Copy link
Member

Choose a reason for hiding this comment

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

TIL, this is very cool!

@mirka mirka marked this pull request as ready for review December 26, 2024 12:13
@mirka mirka requested a review from a team December 26, 2024 12:13
Copy link

github-actions bot commented Dec 26, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <[email protected]>
Co-authored-by: tyxla <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

LGTM, nice 👍

Comment on lines +17 to +19
json2md.converters.md = ( input ) => {
return input?.trim() || '';
};
Copy link
Member

Choose a reason for hiding this comment

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

TIL, this is very cool!

@@ -49,5 +46,5 @@ export function generateMarkdownDocs( { typeDocs, subcomponentTypeDocs } ) {

return json2md(
[ ...mainDocsJson, ...subcomponentDocsJson ].filter( Boolean )
);
).replace( /\n+$/gm, '\n' ); // clean unnecessary consecutive newlines
Copy link
Member

Choose a reason for hiding this comment

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

Noting that this cleans up only trailing ones, maybe we want to update the comment to reflect that?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a global + multiline regex, intended to remove all excessive newlines within in the entire readme output.

@mirka mirka merged commit 5af740f into trunk Dec 26, 2024
71 of 73 checks passed
@mirka mirka deleted the autogen-readme-lists branch December 26, 2024 16:36
@github-actions github-actions bot added this to the Gutenberg 20.0 milestone Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants