diff --git a/server/commands/documentImporter.ts b/server/commands/documentImporter.ts index 46ba48b46..53554e6f9 100644 --- a/server/commands/documentImporter.ts +++ b/server/commands/documentImporter.ts @@ -179,7 +179,6 @@ async function documentImporter({ let title = fileName.replace(/\.[^/.]+$/, ""); let text = await fileInfo.getMarkdown(content); - text = text.trim(); // find and extract emoji near the beginning of the document. const regex = emojiRegex(); @@ -191,17 +190,18 @@ async function documentImporter({ // If the first line of the imported text looks like a markdown heading // then we can use this as the document title rather than the file name. - if (text.startsWith("# ")) { + if (text.trim().startsWith("# ")) { const result = parseTitle(text); title = result.title; text = text + .trim() .replace(new RegExp(`#\\s+${escapeRegExp(title)}`), "") .trimStart(); } // Replace any
generated by the turndown plugin with escaped newlines // to match our hardbreak parser. - text = text.replace(/
/gi, "\\n"); + text = text.trim().replace(/
/gi, "\\n"); text = await DocumentHelper.replaceImagesWithAttachments( text,