From 67fc712d14c42ac2054b5832e0cc9ab75719c012 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 7 Feb 2012 01:14:40 +0100 Subject: [PATCH] Clean up trailing whitespace after rendering HTML in shr (shr-remove-trailing-whitespace): New function. (shr-insert-document): Use it to clean up trailing whitespace as the final step (bug#10714). --- lisp/ChangeLog | 3 +++ lisp/shr.el | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7283576a4..cc5ac49d2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -2,6 +2,9 @@ * shr.el (shr-insert-document): Add doc string. (shr-visit-file): Ditto. + (shr-remove-trailing-whitespace): New function. + (shr-insert-document): Use it to clean up trailing whitespace as the + final step (bug#10714). 2012-02-06 Lars Ingebrigtsen diff --git a/lisp/shr.el b/lisp/shr.el index 26755f868..deaef1d3f 100644 --- a/lisp/shr.el +++ b/lisp/shr.el @@ -144,11 +144,25 @@ cid: URL as the argument.") DOM should be a parse tree as generated by `libxml-parse-html-region' or similar." (setq shr-content-cache nil) - (let ((shr-state nil) + (let ((start (point)) + (shr-state nil) (shr-start nil) (shr-base nil) (shr-width (or shr-width (window-width)))) - (shr-descend (shr-transform-dom dom)))) + (shr-descend (shr-transform-dom dom)) + (shr-remove-trailing-whitespace start (point)))) + +(defun shr-remove-trailing-whitespace (start end) + (save-restriction + (narrow-to-region start end) + (delete-trailing-whitespace) + (goto-char start) + (while (not (eobp)) + (end-of-line) + (dolist (overlay (overlays-at (point))) + (when (overlay-get overlay 'before-string) + (overlay-put overlay 'before-string nil))) + (forward-line 1)))) (defun shr-copy-url () "Copy the URL under point to the kill ring. -- 2.25.1