Gnus development mailing list
 help / color / mirror / Atom feed
* Prevent nnrss from generating text/plain parts for HTML text
@ 2006-01-02 17:41 Mark Plaksin
  2006-01-02 17:51 ` Mark Plaksin
  2006-01-04  3:36 ` Katsumi Yamaoka
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Plaksin @ 2006-01-02 17:41 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 789 bytes --]

nnrss would be better if it did not generate text/plain parts for items
that contain HTML.  As-is, when you discourage HTML and an item contains
HTML you see the unrendered HTML first.  K v will show you the HTML version
but it's extra keystrokes.

I use the this (from Katsumi :) to discourage HTML:

(setq gnus-buttonized-mime-types
      '("multipart/alternative" "multipart/signed")
      mm-discouraged-alternatives
      '("text/html" "image/.*"))

Boing Boing's RSS items (from http://boingboing.net/index.xml) are always
HTML so I always have to hit K v to read them.

I don't know the best way to check for HTML in elisp.  I've attached a
patch which uses a regexp to do the job.  The patch works OK for me but I
don't think it's ideal.  What's a better way to do this?

Thanks!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: nnrss textplain --]
[-- Type: text/x-patch, Size: 3597 bytes --]

--- nnrss.el.orig	2005-12-21 12:43:03.000000000 -0500
+++ nnrss.el	2006-01-02 12:30:51.000000000 -0500
@@ -208,40 +208,47 @@
 	      rfc2047-encode-encoded-words body)
 	  (when (or text link enclosure comments)
 	    (insert "\n")
-	    (insert "<#multipart type=alternative>\n"
-		    "<#part type=\"text/plain\">\n")
-	    (setq body (point))
-	    (when text
-	      (insert text)
-	      (goto-char body)
-	      ;; See `nnrss-check-group', which inserts "<br /><br />".
-	      (if (search-forward "<br /><br />" nil t)
-		  (if (eobp)
-		      (replace-match "\n")
-		    (replace-match "\n\n")
-		    (let ((fill-column default-fill-column)
-			  (window (get-buffer-window nntp-server-buffer)))
-		      (when window
-			(setq fill-column
-			      (max 1 (/ (* (window-width window) 7) 8))))
-		      (fill-region (point) (point-max))
-		      (goto-char (point-max))
-		      ;; XEmacs version of `fill-region' inserts newline.
-		      (unless (bolp)
-			(insert "\n"))))
-		(goto-char (point-max))
-		(insert "\n"))
-	      (when (or link enclosure)
-		(insert "\n")))
-	    (when link
-	      (insert link "\n"))
-	    (when enclosure
-	      (insert (car enclosure) " "
-		      (nth 2 enclosure) " "
-		      (nth 3 enclosure) "\n"))
-	    (when comments
-	      (insert comments "\n"))
-	    (setq body (buffer-substring body (point)))
+	    (insert "<#multipart type=alternative>\n")
+            ;; If text contains HTML, don't generate a text/plain part
+            ;; FIXME:  The regexp is not very smart.  A regexp probably isn't
+            ;; the right thing to use anyhow.  It means any article which has
+            ;; had "<br /><br />" inserted by nnrss-check-group will have no
+            ;; text/plain part.
+            (if (not (string-match "<[a-zA-Z]+[^>]*>" text))
+                (progn
+                  (insert "<#part type=\"text/plain\">\n")
+                  (setq body (point))
+                  (when text
+                    (insert text)
+                    (goto-char body)
+                    ;; See `nnrss-check-group', which inserts "<br /><br />".
+                    (if (search-forward "<br /><br />" nil t)
+                        (if (eobp)
+                            (replace-match "\n")
+                          (replace-match "\n\n")
+                          (let ((fill-column default-fill-column)
+                                (window (get-buffer-window nntp-server-buffer)))
+                            (when window
+                              (setq fill-column
+                                    (max 1 (/ (* (window-width window) 7) 8))))
+                            (fill-region (point) (point-max))
+                            (goto-char (point-max))
+                            ;; XEmacs version of `fill-region' inserts newline.
+                            (unless (bolp)
+                              (insert "\n"))))
+                      (goto-char (point-max))
+                      (insert "\n"))
+                    (when (or link enclosure)
+                      (insert "\n")))
+                  (when link
+                    (insert link "\n"))
+                  (when enclosure
+                    (insert (car enclosure) " "
+                            (nth 2 enclosure) " "
+                            (nth 3 enclosure) "\n"))
+                  (when comments
+                    (insert comments "\n"))
+                  (setq body (buffer-substring body (point)))))
 	    (insert "<#/part>\n"
 		    "<#part type=\"text/html\">\n"
 		    "<html><head></head><body>\n")

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Prevent nnrss from generating text/plain parts for HTML text
  2006-01-02 17:41 Prevent nnrss from generating text/plain parts for HTML text Mark Plaksin
@ 2006-01-02 17:51 ` Mark Plaksin
  2006-01-04  3:36 ` Katsumi Yamaoka
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Plaksin @ 2006-01-02 17:51 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 392 bytes --]

Mark Plaksin <happy@mcplaksin.org> writes:

> I don't know the best way to check for HTML in elisp.  I've attached a
> patch which uses a regexp to do the job.  The patch works OK for me but I
> don't think it's ideal.  What's a better way to do this?

Oops--that patch failed when the text of an item was empty (e.g., some
items in del.icio.us feeds).  Here's a new patch which fixes that.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: nnrss textplain --]
[-- Type: text/x-patch, Size: 3630 bytes --]

--- nnrss.el.orig	2005-12-21 12:43:03.000000000 -0500
+++ nnrss.el	2006-01-02 12:44:33.000000000 -0500
@@ -208,40 +208,48 @@
 	      rfc2047-encode-encoded-words body)
 	  (when (or text link enclosure comments)
 	    (insert "\n")
-	    (insert "<#multipart type=alternative>\n"
-		    "<#part type=\"text/plain\">\n")
-	    (setq body (point))
-	    (when text
-	      (insert text)
-	      (goto-char body)
-	      ;; See `nnrss-check-group', which inserts "<br /><br />".
-	      (if (search-forward "<br /><br />" nil t)
-		  (if (eobp)
-		      (replace-match "\n")
-		    (replace-match "\n\n")
-		    (let ((fill-column default-fill-column)
-			  (window (get-buffer-window nntp-server-buffer)))
-		      (when window
-			(setq fill-column
-			      (max 1 (/ (* (window-width window) 7) 8))))
-		      (fill-region (point) (point-max))
-		      (goto-char (point-max))
-		      ;; XEmacs version of `fill-region' inserts newline.
-		      (unless (bolp)
-			(insert "\n"))))
-		(goto-char (point-max))
-		(insert "\n"))
-	      (when (or link enclosure)
-		(insert "\n")))
-	    (when link
-	      (insert link "\n"))
-	    (when enclosure
-	      (insert (car enclosure) " "
-		      (nth 2 enclosure) " "
-		      (nth 3 enclosure) "\n"))
-	    (when comments
-	      (insert comments "\n"))
-	    (setq body (buffer-substring body (point)))
+	    (insert "<#multipart type=alternative>\n")
+            ;; If text contains HTML, don't generate a text/plain part
+            ;; FIXME:  The regexp is not very smart.  A regexp probably isn't
+            ;; the right thing to use anyhow.  It means any article which has
+            ;; had "<br /><br />" inserted by nnrss-check-group will have no
+            ;; text/plain part.
+            (if (and text
+                     (not (string-match "<[a-zA-Z]+[^>]*>" text)))
+                (progn
+                  (insert "<#part type=\"text/plain\">\n")
+                  (setq body (point))
+                  (when text
+                    (insert text)
+                    (goto-char body)
+                    ;; See `nnrss-check-group', which inserts "<br /><br />".
+                    (if (search-forward "<br /><br />" nil t)
+                        (if (eobp)
+                            (replace-match "\n")
+                          (replace-match "\n\n")
+                          (let ((fill-column default-fill-column)
+                                (window (get-buffer-window nntp-server-buffer)))
+                            (when window
+                              (setq fill-column
+                                    (max 1 (/ (* (window-width window) 7) 8))))
+                            (fill-region (point) (point-max))
+                            (goto-char (point-max))
+                            ;; XEmacs version of `fill-region' inserts newline.
+                            (unless (bolp)
+                              (insert "\n"))))
+                      (goto-char (point-max))
+                      (insert "\n"))
+                    (when (or link enclosure)
+                      (insert "\n")))
+                  (when link
+                    (insert link "\n"))
+                  (when enclosure
+                    (insert (car enclosure) " "
+                            (nth 2 enclosure) " "
+                            (nth 3 enclosure) "\n"))
+                  (when comments
+                    (insert comments "\n"))
+                  (setq body (buffer-substring body (point)))))
 	    (insert "<#/part>\n"
 		    "<#part type=\"text/html\">\n"
 		    "<html><head></head><body>\n")

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Prevent nnrss from generating text/plain parts for HTML text
  2006-01-02 17:41 Prevent nnrss from generating text/plain parts for HTML text Mark Plaksin
  2006-01-02 17:51 ` Mark Plaksin
@ 2006-01-04  3:36 ` Katsumi Yamaoka
  2006-01-05  2:38   ` Mark Plaksin
  1 sibling, 1 reply; 4+ messages in thread
From: Katsumi Yamaoka @ 2006-01-04  3:36 UTC (permalink / raw)


>>>>> In <87wthiedd8.fsf@stone.tss.usg.edu>
>>>>>	Mark Plaksin <happy@mcplaksin.org> wrote:

> nnrss would be better if it did not generate text/plain parts for items
> that contain HTML.  As-is, when you discourage HTML and an item contains
> HTML you see the unrendered HTML first.  K v will show you the HTML version
> but it's extra keystrokes.

> I use the this (from Katsumi :) to discourage HTML:

> (setq gnus-buttonized-mime-types
>       '("multipart/alternative" "multipart/signed")
>       mm-discouraged-alternatives
>       '("text/html" "image/.*"))

> Boing Boing's RSS items (from http://boingboing.net/index.xml) are always
> HTML so I always have to hit K v to read them.

> I don't know the best way to check for HTML in elisp.  I've attached a
> patch which uses a regexp to do the job.  The patch works OK for me but I
> don't think it's ideal.  What's a better way to do this?

How about making those variables group parameters?

(eval-after-load "gnus-sum"
  '(setq gnus-newsgroup-variables
	 (append '((gnus-buttonized-mime-types
		    . '("multipart/alternative" "multipart/signed"))
		   (mm-discouraged-alternatives
		    . '("text/html" "image/.*")))
		 gnus-newsgroup-variables)))

(add-to-list 'gnus-parameters
	     '("\\`nnrss:"
	       (gnus-buttonized-mime-types nil)
	       (mm-discouraged-alternatives nil)))

I haven't fully tested them yet, though.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Prevent nnrss from generating text/plain parts for HTML text
  2006-01-04  3:36 ` Katsumi Yamaoka
@ 2006-01-05  2:38   ` Mark Plaksin
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Plaksin @ 2006-01-05  2:38 UTC (permalink / raw)


Katsumi Yamaoka <yamaoka@jpl.org> writes:

>>>>>> In <87wthiedd8.fsf@stone.tss.usg.edu>
>>>>>>	Mark Plaksin <happy@mcplaksin.org> wrote:
>
>> nnrss would be better if it did not generate text/plain parts for items
>> that contain HTML.  As-is, when you discourage HTML and an item contains
>> HTML you see the unrendered HTML first.  K v will show you the HTML version
>> but it's extra keystrokes.
>
>> I use the this (from Katsumi :) to discourage HTML:
>
>> (setq gnus-buttonized-mime-types
>>       '("multipart/alternative" "multipart/signed")
>>       mm-discouraged-alternatives
>>       '("text/html" "image/.*"))
>
>> Boing Boing's RSS items (from http://boingboing.net/index.xml) are always
>> HTML so I always have to hit K v to read them.
>
>> I don't know the best way to check for HTML in elisp.  I've attached a
>> patch which uses a regexp to do the job.  The patch works OK for me but I
>> don't think it's ideal.  What's a better way to do this?
>
> How about making those variables group parameters?
>
> (eval-after-load "gnus-sum"
>   '(setq gnus-newsgroup-variables
> 	 (append '((gnus-buttonized-mime-types
> 		    . '("multipart/alternative" "multipart/signed"))
> 		   (mm-discouraged-alternatives
> 		    . '("text/html" "image/.*")))
> 		 gnus-newsgroup-variables)))
>
> (add-to-list 'gnus-parameters
> 	     '("\\`nnrss:"
> 	       (gnus-buttonized-mime-types nil)
> 	       (mm-discouraged-alternatives nil)))
>
> I haven't fully tested them yet, though.

This works--thanks!

I wonder whether there's any utility to having a text/plain part when
reading RSS feeds.  There must be but I can't quite imagine it!




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-01-05  2:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-02 17:41 Prevent nnrss from generating text/plain parts for HTML text Mark Plaksin
2006-01-02 17:51 ` Mark Plaksin
2006-01-04  3:36 ` Katsumi Yamaoka
2006-01-05  2:38   ` Mark Plaksin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).