5

I'm looking for an option to wrap lines of rendered HTML in w3m when they reach a certain length, say 72 characters. By default the text spans the entire width of the window and reading becomes difficult. Here's a screenshot of how an article looks by default in fullscreen w3m:

w3m crappy long lines

In newsbeuter I was able to get the behavior I wanted easily with text-width 72. The same article with text nicely wrapped in newsbeuter:

newsbeuter nicely wrapped text

Is there a way to achieve this kind of line-wrapping at 72 characters in w3m?

The data for the views above is available at this url:

https://www.quirksmode.org/blog/archives/2017/05/why_the_politic.html

  • Have you tried anything or has your research pointed you in any specific or particular direction for any potential solutions for this problem? – Pimp Juice IT May 11 '17 at 21:41
5
+50

Run w3m with relevant options to dump formatted page to standard output, then pipe the standard output to less command. However, no such options in w3m configuration file.

What options and how

Manual page w3m(1) has mentioned the following options.

   -dump  dump formatted page into stdout

   -cols width
          specify column width (used with -dump)

To set column width at 72, use those options like this:

$ w3m -dump -cols 72 [URL or filename]

Since -dump option produce standard output, you can't really do normal browsing (w3m will dump formatted page and exit). Pipe to less to browse the formatted page.

$ w3m -dump -cols 72 [URL or filename] | less

The last one-line command is all you need.

Normal browsing by w3m

Browse w3m article on Wikipedia using w3m

Formatted page browsing by w3m and less

Browse w3m article on Wikipedia using w3m with dump option and pipe to less

Notice that first-half of the page is wrapped nicely within the column width specified. The screenshots above are browsing this article: w3m on Wikipedia.

Remarks

The -dump option will remove the hyperlinks all together when producing the formatted page. If column width is the only criteria that you need, this option will suffice.

To this answered date, I am not aware of other ways to also preserve the hyperlinks.

  • Would it be possible to get the wrapping right by feeding the html through Newsbeuter to w3m? – dionys Nov 13 '17 at 13:48
  • @dionys I don't think so. Newsbeuter is an RSS/Atom reader, which display the contents from feed and not from HTML page itself. Like this RSS 2.0 feed of source include 'clean' content of articles, but not shown in RSS 1.0 nor Atom (also depends on blog setup). – clearkimura Nov 14 '17 at 16:23
1

You could simply change the terminal's number of columns through stty, e.g., stty cols 72 and then run w3m <url>. That's what I do sometimes.

There are two problems with this, however:

  1. Even if you aliased w3m to stty cols 72 && w3m, you'd still have to reset the line width after your browsing session if you don't want it to stay at 72 columns. This could be automated through a little wrapper script, though.

  2. When you're in an X terminal, the stty setting will be void as soon as you resize the window. (I've tested this in xterm and urxvt.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.