GNU bug report logs - #23057
25.0.92; shr wrongly adds two newlines to div element

Previous Next

Package: emacs;

Reported by: Stephen Berman <stephen.berman <at> gmx.net>

Date: Fri, 18 Mar 2016 21:12:01 UTC

Severity: normal

Tags: fixed

Merged with 22979

Found in versions 25.1.50, 25.0.92

Done: Lars Magne Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 23057 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Stephen Berman <stephen.berman <at> gmx.net>
Cc: 23057 <at> debbugs.gnu.org, Lars Ingebrigtsen <larsi <at> gnus.org>
Subject: Re: bug#23057: 25.0.92; shr wrongly adds two newlines to div element
Date: Sat, 19 Mar 2016 13:59:47 +0100
Hi,

Lars, could you please have a look if it is ok to install this?  This
fix should go to emacs25 (soon).


Thanks,

Michael.


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




This bug report was last modified 9 years and 115 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.