From e5ff58a73aaf34ad81a6338d013da603d82dbe5a Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Sat, 16 May 2026 21:00:41 +0100 Subject: [PATCH] fix(import): only auto-embed links when they're the sole content of their block --- .../import/utils/import-formatter.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apps/server/src/integrations/import/utils/import-formatter.ts b/apps/server/src/integrations/import/utils/import-formatter.ts index 7b8f6892e..f5ce02683 100644 --- a/apps/server/src/integrations/import/utils/import-formatter.ts +++ b/apps/server/src/integrations/import/utils/import-formatter.ts @@ -104,11 +104,18 @@ export function defaultHtmlFormatter($: CheerioAPI, $root: Cheerio) { normalizeTableColumnWidths($, $root); applyConfluenceMarginLeftIndent($, $root); + // Auto-embed only when the is the SOLE meaningful child of its parent + // block (the "naked URL on its own line" pattern editors use as the + // embed-intent signal). Otherwise body-text links to YouTube/Vimeo/Loom + // get silently turned into fullscreen iframes, which is rarely what the + // author wanted — Confluence's storage format has the `widget` macro for + // explicit embeds, handled separately in the API converter. $root.find('a[href]').each((_, el) => { const $el = $(el); const url = $el.attr('href')!; const { provider } = getEmbedUrlAndProvider(url); if (provider === 'iframe') return; + if (!isSoleMeaningfulChild($el, el)) return; const embed = `
`; $el.replaceWith(embed); @@ -124,6 +131,21 @@ export function defaultHtmlFormatter($: CheerioAPI, $root: Cheerio) { }); } +function isSoleMeaningfulChild( + $el: Cheerio, + rawEl: any, +): boolean { + const $parent = $el.parent(); + if ($parent.length === 0) return true; + const others = $parent.contents().toArray().filter((n: any) => { + if (n === rawEl) return false; + if (n.type === 'text') return (n.data ?? '').trim() !== ''; + if (n.type === 'tag' && n.name === 'br') return false; + return true; + }); + return others.length === 0; +} + const COLUMN_LAYOUTS = [ '', '',