Skip to content

Commit 1154882

Browse files
bruno-garciacursoragentromtsngetsantry[bot]
authored
Add example image to Sentry iOS user feedback page (#14503)
<!-- CURSOR_SUMMARY --> > [!NOTE] > Adds alt-text-based image sizing via a new remark plugin, updates image components to prefer manual dimensions, and inserts an example widget image in iOS user feedback docs. > > - **Images/rendering**: > - **Manual sizing precedence**: `src/components/docImage` now prefers explicit `width`/`height` props over URL hash dimensions and passes `isManualDimensions` to the lightbox. > - **Lightbox styling**: `src/components/imageLightbox` respects `isManualDimensions`, applying only provided dimensions (other axis auto) for inline images. > - **MDX pipeline**: > - Add `remark-image-resize.js` and wire it in `src/mdx.ts` to parse size hints from image ALT text (e.g., `=300x200`) and set `width`/`height` attributes. > - **Docs**: > - Add example User Feedback Widget image to `docs/platforms/apple/common/user-feedback/index.mdx`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3e50084. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Roman Zavarnitsyn <[email protected]> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent 82f55c6 commit 1154882

File tree

6 files changed

+83
-7
lines changed

6 files changed

+83
-7
lines changed
99.8 KB
Loading

docs/platforms/apple/common/user-feedback/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ The User Feedback feature allows you to collect user feedback from anywhere insi
1919

2020
The User Feedback widget allows users to submit feedback from anywhere inside your application.
2121

22+
![An example of the User Feedback Widget on iOS =350x](./img/user-feedback-apple-widget.png)
23+
2224
### Pre-requisites
2325

2426
Ensure that your project is set up with Sentry and that you have added the Sentry Cocoa SDK to your project.

src/components/docImage/index.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,30 @@ export default function DocImage({
9999
imgPath = finalSrc;
100100
}
101101

102-
// Parse dimensions from URL hash (works for both internal and external)
103-
const hashDimensions = parseDimensionsFromHash(src);
102+
// Prefer explicit props (coming from MDX attributes) over hash-based dimensions.
103+
// If either width or height prop is provided, treat as manual sizing.
104+
const manualWidth = parseDimension(propsWidth);
105+
const manualHeight = parseDimension(propsHeight);
104106

105-
// Use hash dimensions first, fallback to props
106-
const width = hashDimensions[0] > 0 ? hashDimensions[0] : parseDimension(propsWidth);
107-
const height = hashDimensions[1] > 0 ? hashDimensions[1] : parseDimension(propsHeight);
107+
// If either width or height is specified manually, ignore any hash dimensions entirely
108+
const hasDimensionOverrides = manualWidth != null || manualHeight != null;
109+
const hashDimensions = hasDimensionOverrides ? [] : parseDimensionsFromHash(src);
110+
111+
const inferredWidth = hashDimensions[0] > 0 ? hashDimensions[0] : undefined;
112+
const width = hasDimensionOverrides ? manualWidth : inferredWidth;
113+
114+
const inferredHeight = hashDimensions[1] > 0 ? hashDimensions[1] : undefined;
115+
const height = hasDimensionOverrides ? manualHeight : inferredHeight;
108116

109117
return (
110118
<ImageLightbox
119+
{...props}
111120
src={finalSrc}
112121
imgPath={imgPath}
113122
width={width}
114123
height={height}
124+
hasDimensionOverrides={hasDimensionOverrides}
115125
alt={props.alt ?? ''}
116-
{...props}
117126
/>
118127
);
119128
}

src/components/imageLightbox/index.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface ImageLightboxProps
1414
alt: string;
1515
imgPath: string;
1616
src: string;
17+
hasDimensionOverrides?: boolean;
1718
height?: number;
1819
width?: number;
1920
}
@@ -54,6 +55,7 @@ export function ImageLightbox({
5455
width,
5556
height,
5657
imgPath,
58+
hasDimensionOverrides: hasDimensionOverrides = false,
5759
style,
5860
className,
5961
...props
@@ -97,8 +99,19 @@ export function ImageLightbox({
9799
const imageClassName = isInline
98100
? className
99101
: 'max-h-[90vh] max-w-[90vw] object-contain';
102+
103+
// Apply sizing:
104+
// - If manual: set only provided dimension(s); missing one becomes 'auto'
105+
// - Else: default responsive
106+
// TODO: support other units for overrides
100107
const imageStyle = isInline
101-
? {width: '100%', height: 'auto', ...style}
108+
? hasDimensionOverrides
109+
? {
110+
width: width != null ? `${width}px` : 'auto',
111+
height: height != null ? `${height}px` : 'auto',
112+
...style,
113+
}
114+
: {width: '100%', height: 'auto', ...style}
102115
: {width: 'auto', height: 'auto'};
103116

104117
if (shouldUseNextImage && dimensions) {

src/mdx.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import remarkCodeTitles from './remark-code-title';
3535
import remarkComponentSpacing from './remark-component-spacing';
3636
import remarkExtractFrontmatter from './remark-extract-frontmatter';
3737
import remarkFormatCodeBlocks from './remark-format-code';
38+
import remarkImageResize from './remark-image-resize';
3839
import remarkImageSize from './remark-image-size';
3940
import remarkTocHeadings, {TocNode} from './remark-toc-headings';
4041
import remarkVariables from './remark-variables';
@@ -583,6 +584,7 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
583584
remarkFormatCodeBlocks,
584585
[remarkImageSize, {sourceFolder: cwd, publicFolder: path.join(root, 'public')}],
585586
remarkMdxImages,
587+
remarkImageResize,
586588
remarkCodeTitles,
587589
remarkCodeTabs,
588590
remarkComponentSpacing,

src/remark-image-resize.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {visit} from 'unist-util-visit';
2+
3+
const SIZE_FROM_ALT_RE = /\s*=\s*(?:(\d+)\s*x\s*(\d+)|(\d+)\s*x|x\s*(\d+))\s*$/;
4+
/**
5+
* remark plugin to parse width/height hints from the image ALT text.
6+
*
7+
* This plugin is intended to run AFTER `remark-mdx-images`, so it processes
8+
* mdxJsxTextElement nodes named `img` (i.e., <img /> in MDX).
9+
*
10+
* Supported ALT suffixes (trailing in ALT text):
11+
* ![Alt text =300x200](./image.png)
12+
* ![Alt text =300x](./image.png)
13+
* ![Alt text =x200](./image.png)
14+
*
15+
* Behavior:
16+
* - Extracts the trailing "=WxH" (width-only/height-only also supported).
17+
* - Cleans the ALT text by removing the size suffix.
18+
* - Adds numeric `width`/`height` attributes to the <img> element.
19+
*/
20+
export default function remarkImageResize() {
21+
return tree =>
22+
visit(tree, {type: 'mdxJsxTextElement', name: 'img'}, node => {
23+
// Handle MDX JSX <img> produced by remark-mdx-images
24+
const altIndex = node.attributes.findIndex(a => a && a.name === 'alt');
25+
const altValue =
26+
altIndex !== -1 && typeof node.attributes[altIndex].value === 'string'
27+
? node.attributes[altIndex].value
28+
: null;
29+
if (altValue) {
30+
const sizeMatch = altValue.match(SIZE_FROM_ALT_RE);
31+
if (sizeMatch) {
32+
const [, wBoth, hBoth, wOnlyWithX, hOnlyWithX] = sizeMatch;
33+
const wStr = wBoth || wOnlyWithX || undefined;
34+
const hStr = hBoth || hOnlyWithX || undefined;
35+
const cleanedAlt = altValue.replace(SIZE_FROM_ALT_RE, '').trim();
36+
// set cleaned alt
37+
node.attributes[altIndex] = {
38+
type: 'mdxJsxAttribute',
39+
name: 'alt',
40+
value: cleanedAlt,
41+
};
42+
43+
if (wStr)
44+
node.attributes.push({type: 'mdxJsxAttribute', name: 'width', value: wStr});
45+
if (hStr)
46+
node.attributes.push({type: 'mdxJsxAttribute', name: 'height', value: hStr});
47+
}
48+
}
49+
});
50+
}

0 commit comments

Comments
 (0)