Skip to content

Commit a18b767

Browse files
[getsentry/action-github-commit] Auto commit
1 parent c4f7728 commit a18b767

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

src/components/docImage/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ export default function DocImage({
110110
const width = isManual
111111
? manualWidth
112112
: hashDimensions[0] > 0
113-
? hashDimensions[0]
114-
: undefined;
113+
? hashDimensions[0]
114+
: undefined;
115115
const height = isManual
116116
? manualHeight
117117
: hashDimensions[1] > 0
118-
? hashDimensions[1]
119-
: undefined;
118+
? hashDimensions[1]
119+
: undefined;
120120

121121
return (
122122
<ImageLightbox

src/components/imageLightbox/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function ImageLightbox({
9999
const imageClassName = isInline
100100
? className
101101
: 'max-h-[90vh] max-w-[90vw] object-contain';
102-
102+
103103
// Apply sizing:
104104
// - If manual: set only provided dimension(s); missing one becomes 'auto'
105105
// - Else: default responsive

src/remark-image-resize.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,32 @@ const SIZE_FROM_ALT_RE = /\s*=\s*(\d+)?x?(\d+)?\s*$/;
2121
export default function remarkImageResize() {
2222
return tree =>
2323
visit(tree, {type: 'mdxJsxTextElement', name: 'img'}, node => {
24-
25-
// Handle MDX JSX <img> produced by remark-mdx-images
26-
const altIndex = node.attributes.findIndex(a => a && a.name === 'alt');
27-
const altValue = altIndex !== -1 && typeof node.attributes[altIndex].value === 'string'
28-
? node.attributes[altIndex].value
29-
: null;
30-
if (altValue) {
31-
const m = altValue.match(SIZE_FROM_ALT_RE);
32-
if (m) {
33-
const [, wStr, hStr] = m;
34-
const cleanedAlt = altValue.replace(SIZE_FROM_ALT_RE, '').trim();
35-
// set cleaned alt
36-
node.attributes[altIndex] = {type: 'mdxJsxAttribute', name: 'alt', value: cleanedAlt};
37-
// remove any pre-existing width/height attributes to avoid duplicates
38-
node.attributes = node.attributes.filter(a => !(a && (a.name === 'width' || a.name === 'height')));
39-
if (wStr) node.attributes.push({type: 'mdxJsxAttribute', name: 'width', value: wStr});
40-
if (hStr) node.attributes.push({type: 'mdxJsxAttribute', name: 'height', value: hStr});
24+
// Handle MDX JSX <img> produced by remark-mdx-images
25+
const altIndex = node.attributes.findIndex(a => a && a.name === 'alt');
26+
const altValue =
27+
altIndex !== -1 && typeof node.attributes[altIndex].value === 'string'
28+
? node.attributes[altIndex].value
29+
: null;
30+
if (altValue) {
31+
const m = altValue.match(SIZE_FROM_ALT_RE);
32+
if (m) {
33+
const [, wStr, hStr] = m;
34+
const cleanedAlt = altValue.replace(SIZE_FROM_ALT_RE, '').trim();
35+
// set cleaned alt
36+
node.attributes[altIndex] = {
37+
type: 'mdxJsxAttribute',
38+
name: 'alt',
39+
value: cleanedAlt,
40+
};
41+
// remove any pre-existing width/height attributes to avoid duplicates
42+
node.attributes = node.attributes.filter(
43+
a => !(a && (a.name === 'width' || a.name === 'height'))
44+
);
45+
if (wStr)
46+
node.attributes.push({type: 'mdxJsxAttribute', name: 'width', value: wStr});
47+
if (hStr)
48+
node.attributes.push({type: 'mdxJsxAttribute', name: 'height', value: hStr});
49+
}
4150
}
42-
}
4351
});
4452
}

0 commit comments

Comments
 (0)