diff --git a/src/components/code/CodeExample.jsx b/src/components/code/CodeExample.jsx index 343ac9bc..ee53e312 100644 --- a/src/components/code/CodeExample.jsx +++ b/src/components/code/CodeExample.jsx @@ -36,13 +36,21 @@ 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]*(\\r?\\n|$)`, + '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, __, lineEnding) => { + if (seen) return ''; + seen = true; + return `${indent}${newPropLine}${lineEnding}`; + }); continue; }