Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ export const RichContentRenderer: React.FC<RichContentRendererProps> = memo(func
// Strip line numbers if present
const rawContent = stripLineNumbers(content);

// Convert markdown to HTML if needed
const html = isMarkdown ? markdownToHtml(rawContent) : rawContent;
// Check if content already looks like HTML (has actual HTML tags)
// This detects content from TipTap editor which outputs HTML
const contentIsHtml = /<[a-z][\s\S]*>/i.test(rawContent);

// Check if content looks like HTML
const isHtml = /<[a-z][\s\S]*>/i.test(html);
// Convert to HTML:
// - If content is already HTML, preserve it (markdownToHtml would escape the tags)
// - If content is not HTML (markdown or plain text), convert markdown to HTML
// - isMarkdown prop can force markdown conversion for edge cases
const html = (contentIsHtml && !isMarkdown) ? rawContent : markdownToHtml(rawContent);

Comment on lines +75 to +80

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve plain text when isMarkdown is false

This change now converts any non-HTML content through markdownToHtml even when isMarkdown is false. That means plain text (e.g., code snippets, JSON, or pages stored as plain text) will be interpreted as markdown and rendered with formatting, which can alter or remove literal characters like _ and *. Previously, with isMarkdown false, the renderer preserved the raw text in a <pre> block, so content fidelity was maintained. This is a behavioral regression for any non-markdown page content that includes markdown-like tokens.

Useful? React with 👍 / 👎.

// After conversion, check if we have HTML to render
const hasHtml = /<[a-z][\s\S]*>/i.test(html);

// Sanitize HTML content using allowlist approach
const sanitized = isHtml ? sanitizeHtmlAllowlist(html) : html;
const sanitized = hasHtml ? sanitizeHtmlAllowlist(html) : html;

return { processedHtml: sanitized, hasHtmlContent: isHtml };
return { processedHtml: sanitized, hasHtmlContent: hasHtml };
}, [content, isMarkdown]);

const handleNavigate = () => {
Expand Down