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:
2025-09-11 16:53:05 +02:00
parent 350c3f6160
commit 1980b8d305
5 changed files with 222 additions and 204 deletions

View File

@@ -107,17 +107,23 @@ func (e *Enhancer) findAndInjectNodes(rootNode *html.Node, elem parser.Element,
return
}
// Determine content type: use database type if available, otherwise parser type
contentType := string(elem.Type)
if contentItem != nil {
contentType = contentItem.Type // Database is source of truth
}
// Inject content attributes for the correctly matched node
e.injector.AddContentAttributes(targetNode, elem.ContentID, string(elem.Type))
e.injector.AddContentAttributes(targetNode, elem.ContentID, contentType)
// Inject content if available
if contentItem != nil {
switch elem.Type {
case parser.ContentText:
switch contentItem.Type { // Use database type, not parser type
case "text":
e.injector.injectTextContent(targetNode, contentItem.Value)
case parser.ContentMarkdown:
case "markdown":
e.injector.injectMarkdownContent(targetNode, contentItem.Value)
case parser.ContentLink:
case "link":
e.injector.injectLinkContent(targetNode, contentItem.Value)
}
}