Skip to content

Commit

Permalink
[api-docs-builder] Preserve multiline prop descriptions with `rawDesc…
Browse files Browse the repository at this point in the history
…riptions` option (#44737)
  • Loading branch information
vladmoroz authored Dec 11, 2024
1 parent 2a8ba74 commit 6b5d751
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/api-docs-builder/buildApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ export function escapeEntities(value: string) {
export function escapeCell(value: string) {
return rawDescriptionsCurrent ? value : _escapeCell(value);
}
export function removeNewLines(value: string) {
return rawDescriptionsCurrent ? value : value.replace(/\r*\n/g, ' ');
}
export function joinUnionTypes(value: string[]) {
// Use unopinionated formatting for raw descriptions
return rawDescriptionsCurrent ? value.join(' | ') : value.join('<br>&#124;&nbsp;');
Expand Down
4 changes: 2 additions & 2 deletions packages/api-docs-builder/utils/generatePropDescription.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as doctrine from 'doctrine';
import * as recast from 'recast';
import { PropTypeDescriptor } from 'react-docgen';
import { escapeCell } from '../buildApi';
import { escapeCell, removeNewLines } from '../buildApi';
import {
isElementTypeAcceptingRefProp,
isElementAcceptingRefProp,
Expand Down Expand Up @@ -129,7 +129,7 @@ export default function generatePropDescription(
// Remove new lines from tag descriptions to avoid markdown errors.
annotation.tags.forEach((tag) => {
if (tag.description) {
tag.description = tag.description.replace(/\r*\n/g, ' ');
tag.description = removeNewLines(tag.description);
}
});

Expand Down

0 comments on commit 6b5d751

Please sign in to comment.