Replace html2text with fast_html2md + tui-markdown for styled email preview
HTML emails are now converted to markdown then rendered with rich formatting (bold, italic, headings, links) in the preview pane via tui-markdown. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2214b15f44
commit
23f179df24
4 changed files with 902 additions and 129 deletions
1016
Cargo.lock
generated
1016
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -12,6 +12,7 @@ serde = { version = "1.0", features = ["derive"] }
|
|||
toml = "1.0"
|
||||
chrono = "0.4"
|
||||
mailparse = "0.15"
|
||||
html2text = "0.14"
|
||||
fast_html2md = "0.0"
|
||||
tui-markdown = "0.3"
|
||||
quoted_printable = "0.5"
|
||||
regex = "1"
|
||||
|
|
@ -205,9 +205,10 @@ fn extract_plain_text(raw: &[u8]) -> Result<String, String> {
|
|||
if let Some(text) = find_part(&parsed, "text/plain") {
|
||||
return Ok(clean_text(&text));
|
||||
}
|
||||
// Fall back to text/html rendered as text
|
||||
// Fall back to text/html converted to markdown
|
||||
if let Some(html) = find_part(&parsed, "text/html") {
|
||||
return Ok(clean_text(&html_to_text(&html)));
|
||||
let md = html2md::rewrite_html(&html, false);
|
||||
return Ok(clean_text(&md));
|
||||
}
|
||||
// Last resort: top-level body
|
||||
parsed.get_body().map(|s| clean_text(&s)).map_err(|e| e.to_string())
|
||||
|
|
@ -237,6 +238,3 @@ fn find_part(mail: &mailparse::ParsedMail, mime_type: &str) -> Option<String> {
|
|||
None
|
||||
}
|
||||
|
||||
fn html_to_text(html: &str) -> String {
|
||||
html2text::from_read(html.as_bytes(), 1000).unwrap_or_else(|_| html.to_string())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,9 +257,9 @@ pub fn main(config: &Config, terminal: &mut Terminal<CrosstermBackend<Stdout>>)
|
|||
|
||||
// --- Bottom: Email preview ---
|
||||
let preview_text = if body_loading {
|
||||
"Loading...".to_string()
|
||||
ratatui::text::Text::raw("Loading...")
|
||||
} else {
|
||||
preview_body.clone()
|
||||
tui_markdown::from_str(&preview_body)
|
||||
};
|
||||
let preview = Paragraph::new(preview_text)
|
||||
.block(Block::default().title("Preview").borders(Borders::ALL).border_style(preview_border))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue