Subject: bug#23057: 25.0.92; shr wrongly adds two newlines to div element

From: Michael Heerdegen <[email-masked]>
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))
>