Fix `org-my-html-svg-contents' error reporting and clean up
This commit is contained in:
parent
59bc902bdb
commit
8857f4c45a
|
@ -38,7 +38,6 @@
|
||||||
|
|
||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
(require 'ox-html)
|
(require 'ox-html)
|
||||||
(require 'nxml-mode)
|
|
||||||
|
|
||||||
|
|
||||||
;;; Define Backend
|
;;; Define Backend
|
||||||
|
@ -117,13 +116,13 @@ lists of SVG files to include in and/or to exclude from embedding."
|
||||||
|
|
||||||
(defun org-my-html-svg-contents (path)
|
(defun org-my-html-svg-contents (path)
|
||||||
"Return the SVG contents of the file named PATH."
|
"Return the SVG contents of the file named PATH."
|
||||||
;; https://emacs.stackexchange.com/a/57433
|
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert-file-contents path)
|
(insert-file-contents path)
|
||||||
(with-syntax-table nxml-mode-syntax-table
|
;; Delete text preceding something starting as an SVG root element.
|
||||||
;; Barf if contents contains no valid SVG.
|
;; See https://emacs.stackexchange.com/a/57433 the for original code.
|
||||||
(while (and (search-forward "<svg")
|
(let ((case-fold-search t))
|
||||||
(nth 8 (syntax-ppss)))))
|
(unless (search-forward "<svg" nil 'noerror)
|
||||||
|
(user-error "Can't find an SVG root element in file `%s'." path)))
|
||||||
(delete-region (point-min) (match-beginning 0))
|
(delete-region (point-min) (match-beginning 0))
|
||||||
(buffer-string)))
|
(buffer-string)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue