Skip to content

Commit ffb9a04

Browse files
authored
feat(web): Make paths to assets into URLs for easy copy-pasting (#1680)
1 parent 87e0cf7 commit ffb9a04

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

apps/web/src/components/component-view.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export const ComponentView: React.FC<ComponentViewProps> = ({
151151
);
152152
};
153153

154+
const srcAttributeRegex = /src\s*=\s*"(?<URI>\/static.+)"/gm;
155+
154156
const CodeView = ({ component }: { component: ImportedComponent }) => {
155157
const [selectedCodeVariant, setSelectedCodeVariant] =
156158
React.useState<CodeVariant>("html");
@@ -176,7 +178,12 @@ const CodeView = ({ component }: { component: ImportedComponent }) => {
176178

177179
let code = "";
178180
if (selectedCodeVariant in component.code) {
179-
code = component.code[selectedCodeVariant] ?? "";
181+
// Resets the regex so that it doesn't break in subsequent runs
182+
srcAttributeRegex.lastIndex = 0;
183+
code = (component.code[selectedCodeVariant] ?? "").replaceAll(
184+
srcAttributeRegex,
185+
(_match, uri) => `src="https://react.email${uri}"`,
186+
);
180187
} else {
181188
throw new Error("The code variant selected is not available", {
182189
cause: {

0 commit comments

Comments
 (0)