fix(editor): show SVGs without a fixed width in the rich markdown editor

The image wrapper was inline-block, so it sized itself from the image's
natural width. An SVG with a viewBox but no absolute width has none, so
the wrapper and the image collapsed to 0x0. Keep the wrapper inline so
the image sizes against the paragraph, as it does in the preview.
This commit is contained in:
Kelvin Amoaba
2026-11-10 18:43:57 +00:00
parent 7d52a73873
commit e965e44c99
@@ -125,13 +125,15 @@ export function createRichMarkdownExtensions({
return ({ node, HTMLAttributes, editor }) => {
// A wrapper prevents native image-byte dragging from conflicting with ProseMirror’s schema-node relocation.
const dom = document.createElement('span')
// Keep the image wrapper inline so it cannot break surrounding text onto separate lines.
dom.style.display = 'inline-block'
// Inline, not inline-block: a shrink-to-fit wrapper collapses an SVG that has a viewBox but no width to 0×0.
dom.style.display = 'inline'
dom.style.lineHeight = '0'
dom.style.maxWidth = '100%'
const img = document.createElement('img')
img.draggable = false
// Undo preflight's block, middle-aligned images so text keeps flowing around them as before.
img.style.display = 'inline-block'
img.style.verticalAlign = 'baseline'
let renderedAttributeNames = new Set<string>()
const syncImageAttributes = (attributes: Record<string, unknown>): void => {
const nextNames = new Set<string>()