tats / w3m

Debian's w3m: WWW browsable pager
https://tracker.debian.org/pkg/w3m
Other
869 stars 92 forks source link

Allow turning off center alignment of tables #175

Closed jidanni closed 3 years ago

jidanni commented 3 years ago

Lynx has

       -center
              Toggle center alignment in HTML TABLE.

But for w3m we need to do

$ sed 's/align="center"//' file.html | w3m -T text/html

(Even if we own a wide monitor, we don't always want text pushed so far to the right.)

Boruch-Baum commented 3 years ago

On 2021-03-12 05:35, 積丹尼 Dan Jacobson wrote:

(Even if we own a wide monitor, we don't always want text pushed so far to the right.)

Just a wee slightly off-topic: If you want to operate within the emacs front-end for w3m, your request is easily handled by writing a 'filter' function, and adding an entry for it in emacs variable `w3m-filter-configuration'.

Here's some sample code, possibly more complex than you need:

+BEGIN_SRC emacs-lisp

(defun w3m-filter--left-align-tables (url) "Left align all tables" (goto-char (point-min)) (let (start bound) (while (re-search-forward "<t[^>]+>" nil t) (setq start (match-beginning 0) bound (match-end 0)) (while (re-search-forward "align=\(center\)" bound t) (replace-match "left" nil nil nil 1) (setq bound (- bound 2))) (goto-char start) (while (re-search-forward "align=\(right\)" bound t) (replace-match "left" nil nil nil 1) (setq bound (- bound 1))) (goto-char (1+ bound)))))

(add-to-list 'w3m-filter-configuration '(t "left-align all tables" ".*" w3m-filter--left-align-tables))

+END_SRC

And here's a sample test html file:

+BEGIN_SRC html

hello

cell 1: align=right <= should not be altered cell 2

This paragraph should be aligned center, ie. align=center

+END_SRC

-- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0

jidanni commented 3 years ago

OK, but I get error: (void-variable w3m-filter-configuration), so I had to comment it out on https://www.jidanni.org/comp/configuration/.gnus.el .

Boruch-Baum commented 3 years ago

On 2021-03-14 08:14, 積丹尼 Dan Jacobson wrote:

OK, but add-to-list 'w3m-filter-configuration gives an error there at the bottom of [1]https://www.jidanni.org/comp/configuration/.gnus.el so I had to comment it out.

And it worked? If an entry isn't added to that list, there's no way for emacs-w3m to know that the filter function exists or when to apply it! What error did you receive?

-- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0

jidanni commented 3 years ago

@Boruch-Baum I see. I needed to wrap it in eval-after-load "w3m" OK. but wait, there is even tougher centering that needs to be conquered, like in

o.htm.gz

Boruch-Baum commented 3 years ago

On 2021-03-18 16:30, 積丹尼 Dan Jacobson wrote:

[1]@Boruch-Baum I see. I needed to wrap it in eval-after-load "w3m"

Yes, that is one solution. Emacs being emacs, there are alternatives: 1) emacs-w3m has its own init file (see documentation for variable w3m-init-file'); 2) There's a package calleduse-package' that seems to have become very popular for this kind of thing.

OK. but wait, there is even tougher centering that needs to be conquered, like in

[2]o.htm.gz

I'm unlikely to be the one to get to deal with that, at least any time soon (Erev Shabbos is a wind-down and prepare period for me, next week is likely to be dominated by the usual the pre-Pesach hysteria, the week after is Pesach itself of course).

-- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0

jidanni commented 3 years ago

OK I finally figured it out, as I put in my https://www.jidanni.org/comp/configuration/.emacs :

(require 'w3m-filter) (defun w3m-filter-jidanni-zap-align-center (url) "Move stuff back from center" (w3m-filter-replace-regexp url "align=\"center\"" "" (point-min)) (w3m-filter-replace-regexp url "</?center>" "" (point-min))) (add-to-list 'w3m-filter-configuration '(t "Attempt to shrink tables by jidanni" "" w3m-filter-jidanni-zap-align-center))

(setq mm-text-html-renderer 'w3m); not powerful enough... need: (setq mm-text-html-renderer-alist '((w3m . mm-shr) ; <--the culprit (w3m . mm-inline-text-html-render-with-w3m) (w3m . mm-inline-text-html-render-with-w3m-standalone) (w3m . gnus-article-html)))

Boruch-Baum commented 3 years ago

On 2021-04-08 15:21, 積丹尼 Dan Jacobson wrote:

OK I finally figured it out ...

Good to hear.

(setq mm-text-html-renderer 'w3m); not powerful enough... need: ... '((w3m . mm-shr) ; <--the culprit

Every few years, I let myself get suckered into attempting to use GNUS, and its learning curve and complexity never fail to astound me for something that should be so simple. And the documentation ... phew ... just take a look at the docstring for 'mm-shr' and the commentary at the top of its lisp file ...

If you every get an itch to try an alternative, take a look at 'newsboat' (formerly 'newsbeuter'). It's trivial to start using; it's easy to configure; it plays nicely with external programs (eg. w3m, emacs, emacs-w3m); it has a zillion features, and; it's well documented. If you do, and want some setup tips and macros to start you off, let me know (off-line).

-- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0

tats commented 3 years ago

New option disable_center is now available. e.g. w3m -o disable_center=1

It will be included in Debian bullseye+1.