]> git.eshelyaron.com Git - emacs.git/commitdiff
(shr-insert): Respect non-breaking space in non-<pre> text
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Fri, 25 Mar 2016 15:57:35 +0000 (16:57 +0100)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Fri, 25 Mar 2016 15:57:35 +0000 (16:57 +0100)
* lisp/net/shr.el (shr-insert): Respect non-breaking space in
non-<pre> text.

lisp/net/shr.el
test/data/shr/nonbr.html [new file with mode: 0644]
test/data/shr/nonbr.txt [new file with mode: 0644]

index 60794158024162622b5b98a5f771ed6372830a6e..3adc57397cf4b68604961ff3926c7b4c945cd396 100644 (file)
@@ -554,6 +554,16 @@ size, and full-buffer size."
       (insert string)
       (shr-pixel-column))))
 
+(defsubst shr--translate-insertion-chars ()
+  ;; Remove soft hyphens.
+  (goto-char (point-min))
+  (while (search-forward "­" nil t)
+    (replace-match "" t t))
+  ;; Translate non-breaking spaces into real spaces.
+  (goto-char (point-min))
+  (while (search-forward " " nil t)
+    (replace-match " " t t)))
+
 (defun shr-insert (text)
   (when (and (not (bolp))
             (get-text-property (1- (point)) 'image-url))
@@ -564,14 +574,11 @@ size, and full-buffer size."
       (insert text)
       (save-restriction
        (narrow-to-region start (point))
-       ;; Remove soft hyphens.
-       (goto-char (point-min))
-       (while (search-forward "­" nil t)
-         (replace-match "" t t))
+        (shr--translate-insertion-chars)
        (goto-char (point-max)))))
    (t
     (let ((font-start (point)))
-      (when (and (string-match "\\`[ \t\n\r ]" text)
+      (when (and (string-match "\\`[ \t\n\r]" text)
                 (not (bolp))
                 (not (eq (char-after (1- (point))) ? )))
        (insert " "))
@@ -581,14 +588,11 @@ size, and full-buffer size."
        (save-restriction
          (narrow-to-region start (point))
          (goto-char start)
-         (when (looking-at "[ \t\n\r ]+")
+         (when (looking-at "[ \t\n\r]+")
            (replace-match "" t t))
-         (while (re-search-forward "[ \t\n\r ]+" nil t)
+         (while (re-search-forward "[ \t\n\r]+" nil t)
            (replace-match " " t t))
-         ;; Remove soft hyphens.
-         (goto-char (point-min))
-         (while (search-forward "­" nil t)
-           (replace-match "" t t))
+          (shr--translate-insertion-chars)
          (goto-char (point-max)))
        ;; We may have removed everything we inserted if if was just
        ;; spaces.
diff --git a/test/data/shr/nonbr.html b/test/data/shr/nonbr.html
new file mode 100644 (file)
index 0000000..56282cf
--- /dev/null
@@ -0,0 +1 @@
+<div class="gmail_extra">(progn</div><div class="gmail_extra">  (setq minibuffer-prompt-properties &#39;(read-only t cursor-intangible t face minibuffer-prompt))</div><div class="gmail_extra"><br></div><div class="gmail_extra">  (defun turn-on-cursor-intangible-mode ()</div><div class="gmail_extra">    &quot;Turns on cursor-intangible-mode.&quot;</div><div class="gmail_extra">    (interactive)</div><div class="gmail_extra">    (cursor-intangible-mode 1))</div><div class="gmail_extra">  (define-globalized-minor-mode global-cursor-intangible-mode cursor-intangible-mode turn-on-cursor-intangible-mode)</div><div class="gmail_extra"><br></div><div class="gmail_extra">  (global-cursor-intangible-mode 1))</div><div class="gmail_extra"><br></div>
diff --git a/test/data/shr/nonbr.txt b/test/data/shr/nonbr.txt
new file mode 100644 (file)
index 0000000..0c3cffa
--- /dev/null
@@ -0,0 +1,12 @@
+(progn
+  (setq minibuffer-prompt-properties '(read-only t cursor-intangible t face
+minibuffer-prompt))
+
+  (defun turn-on-cursor-intangible-mode ()
+    "Turns on cursor-intangible-mode."
+    (interactive)
+    (cursor-intangible-mode 1))
+  (define-globalized-minor-mode global-cursor-intangible-mode
+cursor-intangible-mode turn-on-cursor-intangible-mode)
+
+  (global-cursor-intangible-mode 1))