fix: support percentage sizes in wiki link images (#111)#120
Conversation
- Update ATTACHMENT_URL_REGEXP to capture percentage values (e.g., 100%) - Add formatSize helper to correctly handle both pixel and percentage units - Fixes image export with ![[image.png|100%]] syntax 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughUpdated the image attachment URL regex pattern to accept optional percentage-based width and height values, and added formatting logic to append "px" units to non-percentage size values when generating inline HTML styles. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/config.ts (1)
1-2: LGTM! Regex correctly supports percentage sizes.The updated pattern now accepts both pixel values (e.g.,
100) and percentage values (e.g.,50%) for width and height. The regex will correctly match all standard Obsidian image size formats:
![[image.png|100]]→ width only![[image.png|50%]]→ percentage width![[image.png|100x200]]→ width × height![[image.png|100%x50%]]→ percentage dimensions💡 Consider adding a comment documenting supported formats
The regex pattern is complex. A brief comment would help future maintainers understand what formats are supported, especially now that percentages are included:
+// Matches wiki-style image embeds with optional size specifications +// Formats: ![[image.png]], ![[image.png|100]], ![[image.png|50%]], ![[image.png|100x200]], ![[image.png|100%x50%]] export const ATTACHMENT_URL_REGEXP = /!\[\[((.*?)\.(\w+))(?:\s*\|\s*(?<width>\d+%?)\s*(?:[*|x]\s*(?<height>\d+%?))?)?\]\]/g;
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/config.tssrc/utils.ts
🔇 Additional comments (2)
src/utils.ts (2)
774-778: LGTM! Clean helper function.The
formatSizehelper correctly handles both percentage and pixel values. The logic is straightforward: it preserves percentage values unchanged and appends "px" to non-percentage values. Since the regex pattern (\d+%?) ensures only valid numeric values reach this function, edge cases are well-controlled.
779-786: LGTM! Style generation correctly applies formatSize.The conditional logic properly handles all combinations of width and height, applying
formatSizeconsistently to generate valid CSS. The generated inline styles will correctly render both pixel values (e.g.,width: 100px;) and percentage values (e.g.,width: 50%;).
|
Fixes #111 |
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.