From b3669a2675cc84a8aec402324fd52b435dac915a Mon Sep 17 00:00:00 2001 From: Mahesh Sanikommmu Date: Fri, 10 Oct 2025 21:27:58 -0700 Subject: removed unused code and lint issues --- .../memories-utils/html-content-renderer.tsx | 148 ++++++++++++++------- 1 file changed, 98 insertions(+), 50 deletions(-) (limited to 'apps') diff --git a/apps/web/components/memories-utils/html-content-renderer.tsx b/apps/web/components/memories-utils/html-content-renderer.tsx index b64cad75..a8185f44 100644 --- a/apps/web/components/memories-utils/html-content-renderer.tsx +++ b/apps/web/components/memories-utils/html-content-renderer.tsx @@ -23,32 +23,10 @@ const isHTMLContent = (content: string): boolean => { return htmlPatterns.some((pattern) => pattern.test(content)) } -/** - * Detects if content is likely markdown based on common markdown patterns - */ -const isMarkdownContent = (content: string): boolean => { - // Check for markdown patterns like headers, links, code blocks, etc. - const markdownPatterns = [ - /^#{1,6}\s+/m, // Headers - /\[([^\]]+)\]\([^)]+\)/, // Links - /`{1,3}[^`]*`{1,3}/, // Inline code - /^\s*```[\s\S]*?```/m, // Code blocks - /^\s*[\-*+]\s+/m, // Lists - /^\s*\d+\.\s+/m, // Numbered lists - /\*\*([^*]+)\*\*/, // Bold - /_([^_]+)_/, // Italic - /https?:\/\/[^\s]+/, // URLs - /\*\s+|\-\s+/, // List markers - ] - - return markdownPatterns.some((pattern) => pattern.test(content)) -} - export const HTMLContentRenderer = memo( ({ content, className = "" }: HTMLContentRendererProps) => { const { isHTML, isMarkdown, processedContent } = useMemo(() => { const contentIsHTML = isHTMLContent(content) - const contentIsMarkdown = isMarkdownContent(content) if (contentIsHTML) { return { @@ -62,27 +40,31 @@ export const HTMLContentRenderer = memo( let processed = content // Handle terminal commands (lines starting with $) - if (content.includes('\n$ ')) { + if (content.includes("\n$ ")) { // Convert terminal commands to code blocks for better formatting - processed = content.replace(/^\$ (.*$)/gm, '```bash\n$ $1\n```') + processed = content.replace(/^\$ (.*$)/gm, "```bash\n$ $1\n```") } // Handle cases where content looks like JSON but isn't in code blocks - if (content.trim().startsWith('{') && content.includes('"') && content.includes(':')) { + if ( + content.trim().startsWith("{") && + content.includes('"') && + content.includes(":") + ) { // Check if it looks like JSON and wrap it in a code block - const lines = content.split('\n') + const lines = content.split("\n") let inJsonBlock = false - let jsonLines: string[] = [] - let otherLines: string[] = [] + const jsonLines: string[] = [] + const otherLines: string[] = [] for (const line of lines) { - if (line.trim() === '{' || line.trim() === '[') { + if (line.trim() === "{" || line.trim() === "[") { inJsonBlock = true } if (inJsonBlock) { jsonLines.push(line) - if (line.trim() === '}' || line.trim() === ']') { + if (line.trim() === "}" || line.trim() === "]") { inJsonBlock = false } } else { @@ -90,10 +72,15 @@ export const HTMLContentRenderer = memo( } } - if (jsonLines.length > 0 && jsonLines.join('\n').trim()) { - const jsonBlock = jsonLines.join('\n') - const otherContent = otherLines.join('\n') - processed = otherContent + (otherContent ? '\n\n' : '') + '```json\n' + jsonBlock + '\n```' + if (jsonLines.length > 0 && jsonLines.join("\n").trim()) { + const jsonBlock = jsonLines.join("\n") + const otherContent = otherLines.join("\n") + processed = + otherContent + + (otherContent ? "\n\n" : "") + + "```json\n" + + jsonBlock + + "\n```" } } @@ -117,25 +104,86 @@ export const HTMLContentRenderer = memo( if (isMarkdown) { try { const components: Components = { - h1: ({ children }) =>

{children}

, - h2: ({ children }) =>

{children}

, - h3: ({ children }) =>

{children}

, - h4: ({ children }) =>

{children}

, - h5: ({ children }) =>
{children}
, - h6: ({ children }) =>
{children}
, - p: ({ children }) =>

{children}

, - strong: ({ children }) => {children}, - em: ({ children }) => {children}, - code: ({ children, className }) => {children}, + h1: ({ children }) => ( +

+ {children} +

+ ), + h2: ({ children }) => ( +

+ {children} +

+ ), + h3: ({ children }) => ( +

+ {children} +

+ ), + h4: ({ children }) => ( +

+ {children} +

+ ), + h5: ({ children }) => ( +
+ {children} +
+ ), + h6: ({ children }) => ( +
+ {children} +
+ ), + p: ({ children }) => ( +

+ {children} +

+ ), + strong: ({ children }) => ( + + {children} + + ), + em: ({ children }) => ( + {children} + ), + code: ({ children, className }) => ( + + {children} + + ), pre: ({ children }) => ( -
+						
 							{children}
 						
), - blockquote: ({ children }) =>
{children}
, - a: ({ children, href }) => {children}, - ul: ({ children }) => , - ol: ({ children }) =>
    {children}
, + blockquote: ({ children }) => ( +
+ {children} +
+ ), + a: ({ children, href }) => ( + + {children} + + ), + ul: ({ children }) => ( + + ), + ol: ({ children }) => ( +
    + {children} +
+ ), li: ({ children }) =>
  • {children}
  • , } @@ -146,7 +194,7 @@ export const HTMLContentRenderer = memo( ) - } catch (error) { + } catch { // Fallback to plain text if markdown parsing fails return (