Skip to content

Commit 05651d4

Browse files
authored
fix: split pane html conv and table fix (#1246)
## What? Fixes split pane HTML conversion, according to #1213 Also changes in `view/html.go`: - Extracted element loop into `renderHTMLToText` helper. - `processBody` now: if `mimeType == text/html` and direct render is whitespace-only, retry through `markdownToHTML` pre-pass ## Why? Certain emails are not displayed correctly, as pointed by @EmilyxFox. Also, split pane was displaying emails incorrectly not as per #1213 fix. Signed-off-by: drew <me@andrinoff.com>
1 parent 726899a commit 05651d4

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

tui/folder_inbox.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ func (m *FolderInbox) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
353353
}
354354
// Update email with body
355355
email.Body = msg.Body
356+
email.BodyMIMEType = msg.BodyMIMEType
356357
email.Attachments = msg.Attachments
357358
// Create preview pane with column offset for image rendering
358359
previewWidth := m.calculatePreviewWidth()

view/html.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -703,13 +703,36 @@ func processBody(rawBody, mimeType string, inline map[string]string, h1Style, h2
703703
// HTML bodies skip the markdown pre-pass — md4c can mangle attribute-heavy
704704
// or indented HTML (#602-style raw-tag bleed-through). Empty mimeType keeps
705705
// legacy behavior for cached/legacy callers that don't supply one.
706+
directHTML := mimeType == BodyMIMETypeHTML
706707
var htmlBody []byte
707-
if mimeType == BodyMIMETypeHTML {
708+
if directHTML {
708709
htmlBody = []byte(decodedBody)
709710
} else {
710711
htmlBody = markdownToHTML([]byte(decodedBody))
711712
}
712713

714+
result, placements, err := renderHTMLToText(htmlBody, inline, h1Style, h2Style, disableImages)
715+
if err != nil {
716+
return "", nil, err
717+
}
718+
719+
// Some real-world HTML emails (newsletters with table-only layouts and no
720+
// <th>, AWeber-shape bodies) emit no visible content from htmlconv. Pre-
721+
// c11de45, every body went through markdownToHTML first, which happened to
722+
// keep these alive. Retry through the markdown pre-pass when the direct
723+
// HTML path produces nothing.
724+
if directHTML && strings.TrimSpace(result) == "" {
725+
result, placements, err = renderHTMLToText(markdownToHTML([]byte(decodedBody)), inline, h1Style, h2Style, disableImages)
726+
if err != nil {
727+
return "", nil, err
728+
}
729+
}
730+
731+
result = styleQuotedReplies(result)
732+
return bodyStyle.Render(result), placements, nil
733+
}
734+
735+
func renderHTMLToText(htmlBody []byte, inline map[string]string, h1Style, h2Style lipgloss.Style, disableImages bool) (string, []ImagePlacement, error) {
713736
// Parse HTML into structured elements using C parser.
714737
elements, ok := clib.HTMLToElements(string(htmlBody))
715738
if !ok {
@@ -849,10 +872,7 @@ func processBody(rawBody, mimeType string, inline map[string]string, h1Style, h2
849872
result = imgMarkerRegex.ReplaceAllString(result, "")
850873
}
851874

852-
// Style quoted reply sections (for plain text > quotes)
853-
result = styleQuotedReplies(result)
854-
855-
return bodyStyle.Render(result), placements, nil
875+
return result, placements, nil
856876
}
857877

858878
func tableHeaderStyle() lipgloss.Style {

0 commit comments

Comments
 (0)