Merge branch 'no-gnus' of https://git.gnus.org/gnus into no-gnus
[gnus] / lisp / shr.el
index 969d893..deaef1d 100644 (file)
@@ -128,6 +128,7 @@ cid: URL as the argument.")
 ;; Public functions and commands.
 
 (defun shr-visit-file (file)
+  "Parse FILE as an HTML document, and render it in a new buffer."
   (interactive "fHTML file name: ")
   (pop-to-buffer "*html*")
   (erase-buffer)
@@ -139,12 +140,29 @@ cid: URL as the argument.")
 
 ;;;###autoload
 (defun shr-insert-document (dom)
+  "Render the parsed document DOM into the current buffer.
+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.
@@ -480,7 +498,7 @@ the URL of the image to the kill buffer instead."
      ((not url)
       (message "No link under point"))
      ((string-match "^mailto:" url)
-      (browse-url-mailto url))
+      (browse-url-mail url))
      (t
       (browse-url url)))))
 
@@ -566,7 +584,7 @@ the URL of the image to the kill buffer instead."
 ;; url-cache-extract autoloads url-cache.
 (declare-function url-cache-create-filename "url-cache" (url))
 (autoload 'mm-disable-multibyte "mm-util")
-(autoload 'browse-url-mailto "browse-url")
+(autoload 'browse-url-mail "browse-url")
 
 (defun shr-get-image-data (url)
   "Get image data for URL.