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:
@@ -142,15 +142,16 @@ func (i *Injector) injectLinkContent(node *html.Node, content string) {
|
||||
}
|
||||
|
||||
// injectHTMLContent safely injects HTML content into a DOM node
|
||||
// Preserves the original element and only replaces its content
|
||||
func (i *Injector) injectHTMLContent(node *html.Node, htmlContent string) {
|
||||
// Clear existing content
|
||||
// Clear existing content but preserve the element itself
|
||||
i.clearNode(node)
|
||||
|
||||
if htmlContent == "" {
|
||||
return
|
||||
}
|
||||
|
||||
// Wrap content to create valid HTML document for parsing
|
||||
// Wrap content for safe parsing
|
||||
wrappedHTML := "<div>" + htmlContent + "</div>"
|
||||
|
||||
// Parse HTML string
|
||||
@@ -168,7 +169,7 @@ func (i *Injector) injectHTMLContent(node *html.Node, htmlContent string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Move parsed nodes to target element
|
||||
// Move parsed nodes to target element (preserving original element)
|
||||
for child := wrapper.FirstChild; child != nil; {
|
||||
next := child.NextSibling
|
||||
wrapper.RemoveChild(child)
|
||||
|
||||
Reference in New Issue
Block a user