fix: preserve element attributes and styling during markdown injection
Critical fixes: - Fixed HTML injection to preserve original element attributes, classes, and styling - Updated markdown processor to generate inline content instead of wrapped paragraphs - Enhanced content type handling: database type now takes precedence over parser detection - Eliminated nested <p> tags issue that was causing invalid HTML Key improvements: - Elements like <p class='lead insertr' style='color: blue;'> now maintain all attributes - Markdown **bold**, *italic*, [links](url) inject as inline formatted content - Database content type (markdown/text/link) overrides parser auto-detection - Clean HTML output without structural corruption Before: <p class='lead'><p>**bold**</p></p> (broken) After: <p class='lead'>**bold text**</p> (clean) Server remains source of truth for markdown processing with zero runtime overhead.
This commit is contained in:
@@ -3,6 +3,7 @@ package content
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
@@ -57,11 +58,19 @@ func (mp *MarkdownProcessor) ToHTML(markdown string) (string, error) {
|
||||
|
||||
html := buf.String()
|
||||
|
||||
// Clean up goldmark's paragraph wrapping - we want inline content
|
||||
// Remove <p> and </p> tags if the content is wrapped in a single paragraph
|
||||
if len(html) > 7 && html[:3] == "<p>" && html[len(html)-4:] == "</p>" {
|
||||
html = html[3 : len(html)-4]
|
||||
// Clean up goldmark's paragraph wrapping for inline content
|
||||
// If content is wrapped in a single <p> tag, extract just the inner content
|
||||
html = strings.TrimSpace(html)
|
||||
|
||||
if strings.HasPrefix(html, "<p>") && strings.HasSuffix(html, "</p>") {
|
||||
// Check if this is a single paragraph (no other <p> tags inside)
|
||||
inner := html[3 : len(html)-4] // Remove <p> and </p>
|
||||
if !strings.Contains(inner, "<p>") {
|
||||
// Single paragraph - return just the inner content for inline injection
|
||||
return inner, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Multiple paragraphs or other block content - return as-is
|
||||
return html, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user