bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Michael Heerdegen
Subject: bug#23057: 25.0.92; shr wrongly adds two newlines to div element
Date: Sat, 19 Mar 2016 13:59:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.92 (gnu/linux)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]