Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html render with w3m #789

Open
GuillaumeSeren opened this issue Oct 19, 2015 · 17 comments
Open

Html render with w3m #789

GuillaumeSeren opened this issue Oct 19, 2015 · 17 comments

Comments

@GuillaumeSeren
Copy link
Contributor

Hello there,
I am a new user of alot, and already a big fan !

I search to display a bit better, some of the html mail that I may get (some people/company),
didn't like plain text :( so I need a descent display for html and images.

I use is w3m because it can also render image in my terminal (rxvt),
but when I read a mail in alot my html render is very simple, just the text is displayed with no color or images.

Here what I used in ~/.mailcap file:
text/html; w3m -dump -o document_charset=%{charset} '%s'; nametemplate=%s.html; copiousoutput

Maybe w3m is not the better in alot, did someone manage to get it to work ?

@andresmrm
Copy link
Contributor

Salut! =)

This is a problem I'm still wondering how to solve. For now I have two ways to view HTML:

  1. Inside Alot using a mailcap similar to yours
  2. Piping (pipeto) the HTML content to be rendered by a real browser (I set a hotkey for this).

I tried many HTML to text renders, but none seems a good option. w3m is good at keeping text formatting, but sometimes it hides links. And that can be very bad. E.g.:

Hi! Don't forget to check my report.

And I would reply:

Sure! But where is your report?

This happened a few times to me, so I started using Pandoc (pandoc --wrap=preserve --normalize --reference-links -i %s -f html -t plain). It breaks formatting, but marks links in text, so I know there is a link there.

The second path, piping to a browser, is good when you open a message an you realize it's not displaying right. The problem is when you don't realize that, like in the problem described above.

But it would be great to have better console display of messages: bold, italic, colors.
Pandoc turns bold to CAPS, but... it's not the same thing. Colors could be used to mark links in HTML, and it would also help alot with quoted text. Sometimes quoted and new text get mixed, and it gets really hard to read.

@lucc
Copy link
Collaborator

lucc commented Jul 15, 2016

Did any of you try elinks? I am using elinks and did not yet have any problems besides bad formatting (aliment, colors, bold, underline etc) but until now I attributed this to the terminal not being a good place to render html in general :) .

From my .mailcap:

text/html; elinks        %s; nametemplate=%s.html;
text/html; elinks -dump  %s; nametemplate=%s.html; copiousoutput;

I have no technical insight on this but I assume that it is not possible to get w3m to display the images if you -dump / use mailcap's copiosoutput. I assume that w3m can display them only if it has direct access to the terminal device (running in the terminal directly). But when you use the copiousoutput in the mailcap file (what alot does and should do) w3m will see a file or pipe at its output.

@GuillaumeSeren
Copy link
Contributor Author

@andresmrm
Yes I noticed the 'links problem' before, so when I have some doubt I use a better render (ie: browser), to check but it is not a convenient solution.

Originaly I was searching a way of displaying images (as in w3m) in alot, but didn't find a way, I think there could be a way using the framebuffer and python.

@lucc
Maybe elinks do a better job I will try, thanks for the advice

@GuillaumeSeren
Copy link
Contributor Author

@lucc
After trying your mailcap config with elinks, I only get an output with the (-dump) version,
with the other version I get no output at all, and the links are displayed in the bottom which is convenient.

But I try to display a webpage with both w3m and elinks, and it work well with w3m, but I did not get any form of format with elinks, and no image at all, did you manage to display image with elinks ?

@lucc
Copy link
Collaborator

lucc commented Jul 15, 2016

No I did not get images and I also think it is not possible via mimecap file entries (see speculation above).

As far as I understand mailcap the only entry that is relevant for email readers (and other programs that use mailcap to get a rendered version of some data to display themselves) is the copiousoutput one. Sorry for posting the other one as well.

@andresmrm
Copy link
Contributor

Thanks for the tip, Lucas. I had used elinks before and changed for a reason
that I didn't remember. I tested it again these days and now I remember: it
doesn't quote well previous messages. The line width it imposes break them.

@guillaumecherel
Copy link

Hi everyone,
You mention using piping the HTML part of a message to a browser. How do you do that? The command pipeto sends the whole email file which is not HTML. How do you extract the relevant html part?

@andresmrm
Copy link
Contributor

Hi, @guillaumecherel!

I pipe it to a script. =)
And add a hotkey for it in alot:

	v = pipeto /myscripts/input_to_browser.py

@GuillaumeSeren
Copy link
Contributor Author

GuillaumeSeren commented Dec 1, 2016

Hey some life on this issue !
@andresmrm Thank you ! This script is really useful, I'd just try it it works well.

@lucc Sorry for the big delay but I didn't see your reply, I still not find a way of doing text/html rendering in w3m and pull it back into alot, but emacs seems to be able to change its default internal renderer to w3m (I didn't try it), so it could be a way.

@lucc
Copy link
Collaborator

lucc commented Dec 2, 2016

@guillaumecherel about sending only the html part: I started a PR to add a mime tree view to alot it might be useful for this use case. The mime tree view in mutt that is serving as my example can be used to pipe a single mime part to an external command.

The PR is here: #894 (sadly I have little time to work on this right now, hopfuly later in December)

@guillaumecherel
Copy link

@lucc I saw that, and indeed I think it'd be perfect for this use case!

@ersinakinci
Copy link

I implemented a little script to open HTML and other multimedia types on macOS: https://github.com/earksiinni/pipe-mime-to-qlmanage. Instructions are available at the link.

I use this script to read HTML emails in Safari on my Mac while using alot on my remote text-only computer, thanks to SSH forwarding.

@pazz
Copy link
Owner

pazz commented Feb 24, 2020

cute. Thanks for sharing @earksiinni !

ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 13, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 13, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 13, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 13, 2020
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 13, 2020
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 13, 2020
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 13, 2020
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
@ryneeverett
Copy link
Contributor

I'd like to note that the "link hiding" issue can be fixed by implementing terminal hyperlinks in a terminal web browser. @lypanov has a solution that works fairly well, but it's limited by the fact that terminal web browsers currently clobber the information about what is the anchor text for a link. See tats/w3m#116.

ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 23, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 23, 2020
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 23, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Mar 23, 2020
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
ryneeverett added a commit to ryneeverett/alot that referenced this issue May 7, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue May 7, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue May 7, 2020
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
ryneeverett added a commit to ryneeverett/alot that referenced this issue May 27, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue May 27, 2020
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue May 27, 2020
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
@robert-winkler
Copy link

Hi, @guillaumecherel!

I pipe it to a script. =)
And add a hotkey for it in alot:

	v = pipeto /myscripts/input_to_browser.py

great stuff! this script solved my problem with HTML mails. I only modified it slightly to add the .html extension:

fileending = ".html"
htmlfilename = "".join([f.name,fileending])
os.rename(f.name, htmlfilename)
webbrowser.open(htmlfilename)
#webbrowser.open(f.name)

ryneeverett added a commit to ryneeverett/alot that referenced this issue Dec 6, 2021
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Dec 6, 2021
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Jan 26, 2022
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Jan 26, 2022
The most notable use case is piping html to a browser without extra
scripts such as those shared in pazz#789.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Jan 26, 2022
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
ryneeverett added a commit to ryneeverett/alot that referenced this issue Jan 26, 2022
Many browsers (including chromium) require that files end in the '.html'
extension in order to render them.
See <https://bugs.chromium.org/p/chromium/issues/detail?id=777737>.

When using `pipeto --format=mimepart --as_file`, on an html mime part, let's
automatically set the file extension.

This eliminates the need for additional user scripts referenced in
issues such as pazz#789 and pazz#1153.
@lypanov
Copy link

lypanov commented Mar 7, 2023

I'd like to note that the "link hiding" issue can be fixed by implementing terminal hyperlinks in a terminal web browser. @lypanov has a solution that works fairly well, but it's limited by the fact that terminal web browsers currently clobber the information about what is the anchor text for a link. See tats/w3m#116.

I somehow missed this mention sorry. My work around for this issue is to manually parse the References output from elinks and embed it back into the output. Working for pretty much every email I've recieved since 2020 ;)

The script in question:
https://gist.github.com/lypanov/7a71793568fc1175ce5122cac3015cd3

I'll try to get my latest patch set working against current alot sometime this year.

@lypanov
Copy link

lypanov commented Nov 19, 2023

I'll try to look into this shortly as I'd like to get my alot fork on python 3.13 to benefit from some of the speed ups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants