diff --git a/src/lib/cms/content-processor.js b/src/lib/cms/content-processor.js index bbfd8ae1..7c4798a1 100644 --- a/src/lib/cms/content-processor.js +++ b/src/lib/cms/content-processor.js @@ -29,7 +29,7 @@ try { // Configure mdsvex options const mdsvexOptions = { - extensions: ['.md'], + extensions: ['.md', '.txt'], remarkPlugins: [remarkGfm], rehypePlugins: [rehypeSlug], layout: null // We'll handle layout in Svelte components @@ -71,6 +71,83 @@ const processMarkdownWithMDSvex = async (markdown) => { } }; +/** + * Process plain text content and convert to HTML paragraphs + * Supports markdown-style images and links while keeping everything else as plain text + * Treats double line breaks as paragraph boundaries + */ +const processPlainText = (text) => { + // Escape HTML characters for safety + const escapeHtml = (str) => { + return str + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + }; + + // Step 1: Extract markdown images and links before escaping + const placeholders = []; + let textWithPlaceholders = text; + + // Extract images:  + const imageRegex = /!\[([^\]]*)\]\(([^)]+)\)/g; + textWithPlaceholders = textWithPlaceholders.replace(imageRegex, (match, alt, src) => { + const id = `__IMG_PLACEHOLDER_${placeholders.length}__`; + placeholders.push({ + type: 'img', + alt: alt || '', + src: src.trim(), + id + }); + return id; + }); + + // Extract links: [text](url) + const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g; + textWithPlaceholders = textWithPlaceholders.replace(linkRegex, (match, text, href) => { + const id = `__LINK_PLACEHOLDER_${placeholders.length}__`; + placeholders.push({ + type: 'link', + text: text, + href: href.trim(), + id + }); + return id; + }); + + // Step 2: Split on double newlines to get paragraphs + const paragraphs = textWithPlaceholders + .split(/\n\s*\n/) + .map(para => para.trim()) + .filter(para => para.length > 0); + + // Step 3: Wrap each paragraph in
tags, preserving single line breaks as
+ const html = paragraphs
+ .map(para => {
+ const escapedPara = escapeHtml(para);
+ // Convert single line breaks to
tags
+ const withBreaks = escapedPara.replace(/\n/g, '
');
+ return `
${withBreaks}
`; + }) + .join('\n'); + + // Step 4: Replace placeholders with actual HTML tags + let finalHtml = html; + placeholders.forEach(item => { + if (item.type === 'img') { + const imgTag = `+ Multiple items found for this path. Please check your content directory: +
+ ++ To fix this: Rename one of these items to resolve the conflict. +
+ ++ Check your terminal/console for detailed warnings about this conflict. +
+