ox-odt: Improve styles file handling

* lisp/ox-odt.el (org-odt-template): Allow double quotes around file
  name.  Better error handling.  Small refactoring.
This commit is contained in:
Nicolas Goaziou 2018-11-10 19:59:12 +01:00
parent af81211fdc
commit bea916d9f6
1 changed files with 12 additions and 13 deletions

View File

@ -1357,19 +1357,18 @@ original parsed data. INFO is a plist holding export options."
;; Update styles file. ;; Update styles file.
;; Copy styles.xml. Also dump htmlfontify styles, if there is any. ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
;; Write styles file. ;; Write styles file.
(let* ((styles-file (plist-get info :odt-styles-file)) (let* ((styles-file
(styles-file (and (org-string-nw-p styles-file) (pcase (plist-get info :odt-styles-file)
(org-trim styles-file))) (`nil (expand-file-name "OrgOdtStyles.xml" org-odt-styles-dir))
(styles-file (if (string-match-p "\\`(.*)\\'" styles-file) ((and s (pred (string-match-p "\\`(.*)\\'")))
(ignore-errors (read styles-file)) (condition-case nil
styles-file)) (read s)
;; Non-availability of styles.xml is not a critical (error (user-error "Invalid styles file specification: %S" s))))
;; error. For now, throw an error. (filename filename))))
(styles-file (or styles-file
(expand-file-name "OrgOdtStyles.xml"
org-odt-styles-dir)
(error "org-odt: Missing styles file?"))))
(cond (cond
;; Non-availability of styles.xml is not a critical error. For
;; now, throw an error.
((null styles-file) (error "Missing styles file"))
((listp styles-file) ((listp styles-file)
(let ((archive (nth 0 styles-file)) (let ((archive (nth 0 styles-file))
(members (nth 1 styles-file))) (members (nth 1 styles-file)))
@ -1379,7 +1378,7 @@ original parsed data. INFO is a plist holding export options."
(let* ((image-type (file-name-extension member)) (let* ((image-type (file-name-extension member))
(media-type (format "image/%s" image-type))) (media-type (format "image/%s" image-type)))
(org-odt-create-manifest-file-entry media-type member)))))) (org-odt-create-manifest-file-entry media-type member))))))
((and (stringp styles-file) (file-exists-p styles-file)) ((file-exists-p styles-file)
(let ((styles-file-type (file-name-extension styles-file))) (let ((styles-file-type (file-name-extension styles-file)))
(cond (cond
((string= styles-file-type "xml") ((string= styles-file-type "xml")