Skip to content

Enhanced RichDecorator/--colour features: References and Border Colors #131

Description

@tkapias

Intro

I tried many solutions to display html emails in mutt/neomutt's internal pager (elinks, readability tools, pandoc, html2text tools), but there was always some issues with the encoding, colors, references or parsing.

After a few tests today, rust-html2text seems to be the way to go, it's fast and the parsing, format, and encoding are spot on.

Request

I changed colors and styles options in the html2text example to fit my tastes, but I would like to add 3 features to the RichDecorator, used by --colour in the example:

  • Links listed as references, like in the PlainDecorator.
  • References wrap at --wrap-width, to help with long links osc 8.
  • Assign a color to borders and horizontal lines, to dim them.

Would you have time to implement those or give me some leads? (I'm just starting rust)

Extra

My changes to the example (only Reset for colors and style was not working correctly for me):

diff --git a/examples/html2text.rs b/examples/html2text.rs
index 2c14ddf..4ee56b6 100644
--- a/examples/html2text.rs
+++ b/examples/html2text.rs
@@ -22,41 +22,41 @@ fn default_colour_map(annotations: &[RichAnnotation], s: &str) -> String {
         match annotation {
             Default => {}
             Link(_) => {
-                start.push(format!("{}", termion::style::Underline));
-                finish.push(format!("{}", termion::style::Reset));
+                start.push(format!("{}{}", Fg(AnsiValue(153)), termion::style::Underline));
+                finish.push(format!("{}{}", Fg(White), termion::style::NoUnderline));
             }
             Image(_) => {
                 if !have_explicit_colour {
-                    start.push(format!("{}", Fg(Blue)));
-                    finish.push(format!("{}", Fg(Reset)));
+                    start.push(format!("{}{}", Fg(AnsiValue(225)), termion::style::Italic));
+                    finish.push(format!("{}{}", Fg(White), termion::style::NoItalic));
                 }
             }
             Emphasis => {
-                start.push(format!("{}", termion::style::Bold));
-                finish.push(format!("{}", termion::style::Reset));
+                start.push(format!("{}", termion::style::Italic));
+                finish.push(format!("{}", termion::style::NoItalic));
             }
             Strong => {
                 if !have_explicit_colour {
-                    start.push(format!("{}", Fg(LightYellow)));
-                    finish.push(format!("{}", Fg(Reset)));
+                    start.push(format!("{}", termion::style::Bold));
+                    finish.push(format!("{}", termion::style::NoBold));
                 }
             }
             Strikeout => {
                 if !have_explicit_colour {
-                    start.push(format!("{}", Fg(LightBlack)));
-                    finish.push(format!("{}", Fg(Reset)));
+                    start.push(format!("{}{}", Fg(AnsiValue(7)), termion::style::CrossedOut));
+                    finish.push(format!("{}{}", Fg(White), termion::style::NoCrossedOut));
                 }
             }
             Code => {
                 if !have_explicit_colour {
-                    start.push(format!("{}", Fg(Blue)));
-                    finish.push(format!("{}", Fg(Reset)));
+                    start.push(format!("{}{}", Bg(AnsiValue(25)), Fg(AnsiValue(222))));
+                    finish.push(format!("{}{}", Bg(Reset) ,Fg(White)));
                 }
             }
             Preformat(_) => {
                 if !have_explicit_colour {
-                    start.push(format!("{}", Fg(Blue)));
-                    finish.push(format!("{}", Fg(Reset)));
+                    start.push(format!("{}{}", Bg(AnsiValue(25)), Fg(AnsiValue(229))));
+                    finish.push(format!("{}{}", Bg(Reset), Fg(White)));
                 }
             }
             Colour(c) => {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions