From: Stephen Berman <stephen.berman@gmx.net>
To: 23057@debbugs.gnu.org
Subject: bug#23057: 25.0.92; shr wrongly adds two newlines to div element
Date: Fri, 18 Mar 2016 23:18:29 +0100 [thread overview]
Message-ID: <87a8lvig5m.fsf@gmx.net> (raw)
In-Reply-To: <87lh5fijaq.fsf@gmx.net> (Stephen Berman's message of "Fri, 18 Mar 2016 22:10:37 +0100")
On Fri, 18 Mar 2016 22:10:37 +0100 Stephen Berman <stephen.berman@gmx.net> wrote:
> The following patch fixes this display problem for me, but I'm not
> familiar enough either with shr or with all the details of HTML block
> elements to be sure this is a sufficient or even correct fix.
>
> diff --git a/lisp/net/shr.el b/lisp/net/shr.el
> index e943132..d9dcda3 100644
> --- a/lisp/net/shr.el
> +++ b/lisp/net/shr.el
> @@ -812,6 +812,9 @@ shr-ensure-paragraph
> (line-end-position))
> (line-end-position)))))
> (delete-region (match-beginning 0) (match-end 0)))
> + ((eq (dom-tag dom) 'div)
> + ;; <div> contains no block element; do nothing.
> + )
> (t
> (insert "\n\n"))))))
Oops, I overlooked that `dom' is unbound here; it's dynamically bound
when called from shr-tag-div, but that may be a problem elsewhere.
Here's a cleaner alternative, but it's probably too ad hoc for a real
fix:
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index e943132..6350dfb 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -786,7 +786,7 @@ shr-ensure-newline
(unless (zerop (current-column))
(insert "\n")))
-(defun shr-ensure-paragraph ()
+(defun shr-ensure-paragraph (&optional dom)
(unless (bobp)
(let ((prefix (get-text-property (line-beginning-position)
'shr-prefix-length)))
@@ -812,6 +812,10 @@ shr-ensure-paragraph
(line-end-position))
(line-end-position)))))
(delete-region (match-beginning 0) (match-end 0)))
+ ((and dom
+ (eq (dom-tag dom) 'div))
+ ;; <div> contains no block element; do nothing.
+ )
(t
(insert "\n\n"))))))
@@ -1206,7 +1210,7 @@ shr-tag-p
(shr-ensure-paragraph))
(defun shr-tag-div (dom)
- (shr-ensure-paragraph)
+ (shr-ensure-paragraph dom)
(shr-generic dom)
(shr-ensure-newline))
next prev parent reply other threads:[~2016-03-18 22:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-18 21:10 bug#23057: 25.0.92; shr wrongly adds two newlines to div element Stephen Berman
2016-03-18 22:18 ` Stephen Berman [this message]
2016-03-19 12:59 ` Michael Heerdegen
2016-03-20 11:57 ` Lars Magne Ingebrigtsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a8lvig5m.fsf@gmx.net \
--to=stephen.berman@gmx.net \
--cc=23057@debbugs.gnu.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).