Ihor Radchenko writes: [...] > +(defconst org-odt-forbidden-char-re > + (rx (not (in ?\N{U+9} ?\N{U+A} ?\N{U+D} > + (?\N{U+20} . ?\N{U+D7FF}) > + (?\N{U+E000} . ?\N{U+FFFD}) > + (?\N{U+10000} . ?\N{U+10FFFF})))) Indentation mismatch ^ > + "Regexp matching forbidden XML1.0 characters. > +https://www.w3.org/TR/REC-xml/#charsets") > + > (defconst org-odt-schema-dir-list > (list (expand-file-name "./schema/" org-odt-data-dir)) > "List of directories to search for OpenDocument schema files. > @@ -364,6 +374,19 @@ (defgroup org-export-odt nil > :tag "Org Export ODT" > :group 'org-export) > > +(defcustom org-odt-with-forbidden-chars "" > + "String to replace forbidden XML characters. > +When set to t, forbidden characters are retained. > +When set to nil, an error is thrown. > +See `org-odt-forbidden-char-re' for the list of forbidden characters > +that cannot occur inside ODT documents. > + > +You may also consider export filters to perform more fine-grained > +replacements. See info node `(org)Advanced Export Configuration'." > + :package-version '(Org . "9.8") > + :type '(choice (const :tag "Strip forbidden characters" t) According to the docstring, the above tag should say "Leave forbidden characters as-is". See patch which slightly rewords the docstring too. > + (const :tag "Err when forbidden characters encountered" nil) > + (string :tag "Replacement string"))) > > ;;;; Debugging > > @@ -2892,6 +2915,24 @@ (defun org-odt--encode-tabs-and-spaces (line) > (format " " (1- (length s))))) > line)) > > +(defun org-odt--remove-forbidden (text _backend info) > + "Remove forbidden and discouraged characters from TEXT. > +INFO is the communication plist" > + (pcase (plist-get info :odt-with-forbidden-chars) Should we use pcase-exhaustive? > + ((and (pred stringp) rep) > + (prog1 (replace-regexp-in-string org-odt-forbidden-char-re rep text) > + (when (match-string 0 text) The replacement appears to work well on my machine, but there are unnecessary warnings. Run org-odt-export-to-odt on a buffer containing: --8<---------------cut here---------------start------------->8--- * foo bar --8<---------------cut here---------------end--------------->8--- the (match-string 0 text) form inside org-odt--remove-forbidden evals to "(nil) edebug--eval-defun(# nil) apply(edebug--eval-defun # nil) eval-defun(nil) funcall-interactively(eval-defun nil) command-execute(eval-defun) Also with the replace-regexp-in-string design, there will only be one warning even with multiple forbidden characters. See patch below. > + (display-warning > + '(ox-odt ox-odt-with-forbidden-chars) > + (format "Replacing forbidden character '%s' with '%s'" > + (match-string 0 text) rep))))) > + (`nil > + (if (string-match org-odt-forbidden-char-re text) > + (error "Forbidden character '%s' found. See `org-odt-with-forbidden-chars'" > + (match-string 0 text)) > + text)) > + (_ text))) > + > (defun org-odt--encode-plain-text (text &optional no-whitespace-filling) > (dolist (pair '(("&" . "&") ("<" . "<") (">" . ">"))) > (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t))) > -- > 2.47.1