changeset 110024:5428546bbb98

Add a new super-simple HTML renderer based on w3m -halfdump by Lars Magne Ingebrigtsen <larsi@gnus.org>. * gnus-html.el: Start a new super-simple HTML renderer based on w3m.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Mon, 30 Aug 2010 06:13:50 +0000
parents fa10effce8f8
children 5f352fd4346a
files lisp/gnus/ChangeLog lisp/gnus/gnus-html.el
diffstat 2 files changed, 80 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/gnus/ChangeLog	Mon Aug 30 06:10:18 2010 +0000
+++ b/lisp/gnus/ChangeLog	Mon Aug 30 06:13:50 2010 +0000
@@ -1,3 +1,7 @@
+2010-08-29  Lars Magne Ingebrigtsen  <larsi@gnus.org>
+
+	* gnus-html.el: Start a new super-simple HTML renderer based on w3m.
+
 2010-08-28  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
 	* gnus.el (gnus-valid-select-methods): Remove reference to nngoogle,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/gnus/gnus-html.el	Mon Aug 30 06:13:50 2010 +0000
@@ -0,0 +1,76 @@
+;;; gnus-html.el --- Quoted-Printable functions
+
+;; Copyright (C) 2010  Free Software Foundation, Inc.
+
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
+;; Keywords: html, web
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; The idea is to provide a simple, fast and pretty minimal way to
+;; render HTML (including links and images) in a buffer, based on an
+;; external HTML renderer (i.e., w3m).
+
+;;; Code:
+
+;;;###autoload
+(defun gnus-article-html (handle)
+  (let ((article-buffer (current-buffer)))
+    (save-restriction
+      (narrow-to-region (point) (point))
+      (save-excursion
+	(set-buffer (car handle))
+	(call-process-region (point-min) (point-max)
+			     "w3m" 
+			     nil article-buffer nil
+			     "-halfdump"
+			     "-T" "text/html"))
+      (gnus-html-wash-tags))))
+
+(defun gnus-html-wash-tags ()
+  (let (tag parameters string start end)
+    ;;(subst-char-in-region (point-min) (point-max) ?_ ? )
+    (goto-char (point-min))
+    (while (re-search-forward "<\\([^ ]+\\)\\([^>]*\\)>\\([^<]*\\)<[^>]*>" nil t)
+      (setq tag (match-string 1)
+	    parameters (match-string 2)
+	    string (match-string 3)
+	    start (match-beginning 0)
+	    end (+ start (length string)))
+      (replace-match string)
+      (cond
+       ;; Fetch and insert a picture.
+       ((equal tag "img_alt")
+	;;
+	)
+       ;; Add a link.
+       ((equal tag "a")
+	(when (string-match "href=\"\\([^\"]+\\)" parameters)
+	  (setq parameters (match-string 1 parameters))
+	  (gnus-article-add-button start end
+				   'browse-url parameters)
+	  (let ((overlay (gnus-make-overlay start end)))
+	    (gnus-overlay-put overlay 'evaporate t)
+	    (gnus-overlay-put overlay 'gnus-button-url parameters)
+	    (when gnus-article-mouse-face
+	      (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))))
+       ;; Whatever.  Just ignore the tag.
+       (t
+	(replace-match string))))))
+
+;;; gnus-html.el ends here