ox-odt: Fix verse environment

* lisp/ox-odt.el (org-odt--encode-tabs-and-spaces): Small refactoring.
(org-odt-verse-block): Only replace leading blanks.
This commit is contained in:
Nicolas Goaziou 2017-01-12 15:27:39 +01:00
parent 0e626313e1
commit 1749dfe091
1 changed files with 10 additions and 17 deletions

View File

@ -2882,15 +2882,10 @@ contextual information."
(defun org-odt--encode-tabs-and-spaces (line) (defun org-odt--encode-tabs-and-spaces (line)
(replace-regexp-in-string (replace-regexp-in-string
"\\([\t]\\|\\([ ]+\\)\\)" "\\(\t\\| \\{2,\\}\\)"
(lambda (s) (lambda (s)
(cond (if (string= s "\t") "<text:tab/>"
((string= s "\t") "<text:tab/>") (format " <text:s text:c=\"%d\"/>" (1- (length s)))))
(t (let ((n (length s)))
(cond
((= n 1) " ")
((> n 1) (concat " " (format "<text:s text:c=\"%d\"/>" (1- n))))
(t ""))))))
line)) line))
(defun org-odt--encode-plain-text (text &optional no-whitespace-filling) (defun org-odt--encode-plain-text (text &optional no-whitespace-filling)
@ -3673,15 +3668,13 @@ channel."
"Transcode a VERSE-BLOCK element from Org to ODT. "Transcode a VERSE-BLOCK element from Org to ODT.
CONTENTS is verse block contents. INFO is a plist holding CONTENTS is verse block contents. INFO is a plist holding
contextual information." contextual information."
;; Add line breaks to each line of verse. (format "\n<text:p text:style-name=\"OrgVerse\">%s</text:p>"
(setq contents (replace-regexp-in-string (replace-regexp-in-string
"\\(<text:line-break/>\\)?[ \t]*\n" ;; Replace leading tabs and spaces.
"<text:line-break/>" contents)) "^[ \t]+" #'org-odt--encode-tabs-and-spaces
;; Replace tabs and spaces. ;; Add line breaks to each line of verse.
(setq contents (org-odt--encode-tabs-and-spaces contents)) (replace-regexp-in-string
;; Surround it in a verse environment. "\\(<text:line-break/>\\)?[ \t]*$" "<text:line-break/>" contents))))
(format "\n<text:p text:style-name=\"%s\">%s</text:p>"
"OrgVerse" contents))