Gnus development mailing list
 help / color / mirror / Atom feed
From: Mark Plaksin <happy@usg.edu>
Subject: Re: Prevent nnrss from generating text/plain parts for HTML text
Date: Mon, 02 Jan 2006 12:51:37 -0500	[thread overview]
Message-ID: <87sls6ecwm.fsf@stone.tss.usg.edu> (raw)
In-Reply-To: <87wthiedd8.fsf@stone.tss.usg.edu>

[-- 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")

  reply	other threads:[~2006-01-02 17:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-02 17:41 Mark Plaksin
2006-01-02 17:51 ` Mark Plaksin [this message]
2006-01-04  3:36 ` Katsumi Yamaoka
2006-01-05  2:38   ` Mark Plaksin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sls6ecwm.fsf@stone.tss.usg.edu \
    --to=happy@usg.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).