From 1dae7b1737fdc11a8e1f45b8a9d92b24fd843ba7 Mon Sep 17 00:00:00 2001 From: Stefan Hardegger Date: Sat, 21 Mar 2026 15:36:54 +0100 Subject: [PATCH] Imrove Imports --- .../storycove/service/PDFImportService.java | 4 +++- .../src/components/stories/SlateEditor.tsx | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/storycove/service/PDFImportService.java b/backend/src/main/java/com/storycove/service/PDFImportService.java index 9622bc5..ce0ca39 100644 --- a/backend/src/main/java/com/storycove/service/PDFImportService.java +++ b/backend/src/main/java/com/storycove/service/PDFImportService.java @@ -212,7 +212,9 @@ public class PDFImportService { for (String para : paragraphs) { String trimmed = para.trim(); if (!trimmed.isEmpty() && !isLikelyHeaderFooter(trimmed)) { - htmlContent.append("

").append(escapeHtml(trimmed)).append("

\n"); + // Normalize soft line wraps (single newlines from PDF layout) to spaces + String normalized = trimmed.replaceAll("[ \t]*\n[ \t]*", " ").replaceAll(" {2,}", " ").trim(); + htmlContent.append("

").append(escapeHtml(normalized)).append("

\n"); } } } diff --git a/frontend/src/components/stories/SlateEditor.tsx b/frontend/src/components/stories/SlateEditor.tsx index 580d144..be58243 100644 --- a/frontend/src/components/stories/SlateEditor.tsx +++ b/frontend/src/components/stories/SlateEditor.tsx @@ -89,6 +89,26 @@ const htmlToSlate = (html: string): Descendant[] => { if (tag === 'em' || tag === 'i') newMarks.italic = true; if (tag === 'u') newMarks.underline = true; if (tag === 's' || tag === 'del' || tag === 'strike') newMarks.strikethrough = true; + + // Also detect bold/italic from inline CSS styles (e.g. pasted web content) + const style = el.getAttribute('style'); + if (style) { + const fwMatch = style.match(/font-weight\s*:\s*([^;]+)/i); + if (fwMatch) { + const fw = fwMatch[1].trim().toLowerCase(); + if (fw === 'bold' || fw === 'bolder' || Number(fw) >= 600) { + newMarks.bold = true; + } + } + const fsMatch = style.match(/font-style\s*:\s*([^;]+)/i); + if (fsMatch) { + const fs = fsMatch[1].trim().toLowerCase(); + if (fs === 'italic' || fs === 'oblique') { + newMarks.italic = true; + } + } + } + el.childNodes.forEach(child => processNode(child, newMarks)); } };