Skip to content

Commit cfe37ca

Browse files
fix: don't wrap images in a p tag
1 parent f61ad27 commit cfe37ca

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

apps/web/components/Image/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function Image({
8686
height={imageDimensions?.height}
8787
className="image__img"
8888
placeholder="blur"
89-
blurDataURL="data:image/..."
89+
blurDataURL="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAv/xAAhEAACAQMDBQAAAAAAAAAAAAABAgMABAUGIWGRkqGx0f/EABUBAQEAAAAAAAAAAAAAAAAAAAMF/8QAGhEAAgIDAAAAAAAAAAAAAAAAAAECEgMRkf/aAAwDAQACEQMRAD8AltJagyeH0AthI5xdrLcNM91BF5pX2HaH9bcfaSXWGaRmknyJckliyjqTzSlT54b6bk+h0R/W5P8AkX9P3/tImuLdVkULl3ybS4U7RK32LGTWjB5qbY8+IKqXqX1rp5nvLr1l4dTrg=="
9090
onError={() => {
9191
setImageError(true);
9292
setLoadingComplete(true);

apps/web/components/MDX/index.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ function createHeading(level) {
104104
return '';
105105
})
106106
.join('');
107-
107+
108108
const slug = slugify(text);
109-
109+
110110
return createElement(`h${level}`, { id: slug }, [
111111
createElement(
112112
'a',
@@ -143,13 +143,33 @@ function createHeading(level) {
143143
}
144144

145145
function Wrapper({ children }) {
146-
if (
147-
children &&
148-
typeof children === 'object' &&
149-
(children.type === RoundedImage || children.type === Image)
150-
) {
151-
return children;
146+
147+
const hasImageComponent = (child) => {
148+
if (!child || typeof child !== 'object') return false;
149+
150+
if (child.type === RoundedImage || child.type === Image) return true;
151+
152+
if (child.type?.displayName === 'RoundedImage' || child.type?.name === 'RoundedImage') return true;
153+
if (child.type?.displayName === 'Image' || child.type?.name === 'Image') return true;
154+
155+
if (child.type === 'img') return true;
156+
157+
return false;
158+
};
159+
160+
if (children && typeof children === 'object' && !Array.isArray(children)) {
161+
if (hasImageComponent(children)) {
162+
return children;
163+
}
152164
}
165+
166+
if (Array.isArray(children)) {
167+
const hasImages = children.some(hasImageComponent);
168+
if (hasImages) {
169+
return <>{children}</>;
170+
}
171+
}
172+
153173
return <p>{children}</p>;
154174
}
155175

0 commit comments

Comments
 (0)