Browse Source

ox-html: Fix verse environment

* lisp/ox-html.el (org-html-verse-block): Do not insert duplicates
  "br" close-tags.  Refactor code.
Nicolas Goaziou 8 years ago
parent
commit
0e626313e1
1 changed files with 10 additions and 14 deletions
  1. 10 14
      lisp/ox-html.el

+ 10 - 14
lisp/ox-html.el

@@ -3592,20 +3592,16 @@ information."
   "Transcode a VERSE-BLOCK element from Org to HTML.
 CONTENTS is verse block contents.  INFO is a plist holding
 contextual information."
-  ;; Replace each newline character with line break.  Also replace
-  ;; each blank line with a line break.
-  (setq contents (replace-regexp-in-string
-		  "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
-		  (replace-regexp-in-string
-		   "\\(\\\\\\\\\\)?[ \t]*\n"
-		   (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
-  ;; Replace each white space at beginning of a line with a
-  ;; non-breaking space.
-  (while (string-match "^[ \t]+" contents)
-    (let* ((num-ws (length (match-string 0 contents)))
-	   (ws (org-html--make-string num-ws " ")))
-      (setq contents (replace-match ws nil t contents))))
-  (format "<p class=\"verse\">\n%s</p>" contents))
+  (format "<p class=\"verse\">\n%s</p>"
+	  ;; Replace leading white spaces with non-breaking spaces.
+	  (replace-regexp-in-string
+	   "^[ \t]+" (lambda (m) (org-html--make-string (length m) "&#xa0;"))
+	   ;; Replace each newline character with line break.  Also
+	   ;; remove any trailing "br" close-tag so as to avoid
+	   ;; duplicates.
+	   (let* ((br (org-html-close-tag "br" nil info))
+		  (re (format "\\(%s\\)[ \t]*$" (regexp-quote br))))
+	     (replace-regexp-in-string re br contents)))))
 
 
 ;;; Filter Functions