Skip to content
Merged
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
14 changes: 12 additions & 2 deletions src/components/code/CodeExample.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,23 @@ function injectPropsIntoCode(usageCode, props, defaultProps, componentName, demo
const newPropLine =
typeof propValue === 'boolean' && propValue === true ? propName : `${propName}=${formattedValue}`;

const simplePropRegex = new RegExp(`(^[ \\t]*)(${propName})(?:=(?:"[^"]*"|\\{[^{}\\n]*\\}))?[ \\t]*$`, 'gm');
const simplePropRegex = new RegExp(
`(^[ \\t]*)(${propName})(?:=(?:"[^"\\n]*"|'[^'\\n]*'|\\{[^{}\\n]*\\}|[^\\s/>]+))?[ \\t]*$`,
'gm'
);

const hasSimpleMatch = simplePropRegex.test(result);
simplePropRegex.lastIndex = 0;

if (hasSimpleMatch) {
result = result.replace(simplePropRegex, `$1${newPropLine}`);
let seen = false;
result = result
.replace(simplePropRegex, (_, indent) => {
if (seen) return '';
seen = true;
return `${indent}${newPropLine}`;
})
.replace(/\n{3,}/g, '\n\n');
Comment thread
Utkarsh-Singhal-26 marked this conversation as resolved.
Outdated
continue;
}

Expand Down
Loading