Skip to content

Commit

Permalink
fix(api-docgen): allow multiple lines description (web-infra-dev#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Mar 25, 2024
1 parent 47a2d6a commit 37e626d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/pink-knives-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rspress/plugin-api-docgen": patch
---

fix(api-docgen): allow multiple lines description
2 changes: 2 additions & 0 deletions e2e/fixtures/api-docgen/src/Button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export type ButtonProps = {
/**
* Whether to disable the button
* - This is extra line a
* - This is extra line b
*/
disabled?: boolean;
/**
Expand Down
2 changes: 2 additions & 0 deletions e2e/tests/api-docgen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ test.describe('api-docgen test', async () => {
// Description
expect(tableContent).toContain('Description');
expect(tableContent).toContain('Whether to disable the button');
expect(tableContent).toContain('- This is extra line a');
expect(tableContent).toContain('- This is extra line b');
expect(tableContent).toContain('Type of Button');

// Type
Expand Down
7 changes: 6 additions & 1 deletion packages/plugin-api-docgen/src/docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ function generateTable(componentDoc: ComponentDoc[], language: 'zh' | 'en') {
return description;
}
};
return `|${[name, getDescription(), getType(), getDefaultValue()]

const formattedDescription = getDescription()
// allow newline
.replace(/\n/g, '
');

return `|${[name, formattedDescription, getType(), getDefaultValue()]
.map(str => str.replace(/(?<!\\)\|/g, '&#124;'))
.join('|')}|`;
});
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-api-docgen/static/global-components/API.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
table {
table-layout: fixed;
width: 100%;

td {
// allow use &#10; to break line
white-space: pre-wrap;
}
}

0 comments on commit 37e626d

Please sign in to comment.