GNU bug report logs -
#23057
25.0.92; shr wrongly adds two newlines to div element
Previous Next
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 #8 received at 23057 <at> debbugs.gnu.org (full text, mbox):
On Fri, 18 Mar 2016 22:10:37 +0100 Stephen Berman <stephen.berman <at> 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))
This bug report was last modified 9 years and 113 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.