From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id oIkbBnh/bmdLowAAe85BDQ:P1 (envelope-from ) for ; Fri, 27 Dec 2024 10:20:40 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id oIkbBnh/bmdLowAAe85BDQ (envelope-from ) for ; Fri, 27 Dec 2024 11:20:40 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; none Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E1A2986086 for ; Fri, 27 Dec 2024 11:20:39 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR7RY-0004mv-HQ; Fri, 27 Dec 2024 05:19:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR7RW-0004mT-6T for emacs-orgmode@gnu.org; Fri, 27 Dec 2024 05:19:42 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR7RR-0008HL-SW for emacs-orgmode@gnu.org; Fri, 27 Dec 2024 05:19:41 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id E412E240027 for ; Fri, 27 Dec 2024 11:19:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1735294773; bh=8kBxX2qMw+MZriFWCqBflmxZq1+C/71ThEypGvX0QqI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=ZJ8Q0lJ8pD95boV3iIKqsNYD9ZguE+6QRNf1wIJMqGogfTzaTbDFuquGYNK8VAEDc KmxjNyu3aqtYZ3Y4NiLWPTkeDB1nRRZzWuRgAB6pB/EC6OnrBNuIRM5MX50HlnK4CS K4eNPVWNC6J/7UsGgxWkYOv6jCVKVl7fxrGGiHw4qowkx/YwqaumwuWDUKqCZpWGYb S8SGqBfeNRV6OkUqes9VhRXI/JOA32HKyGYBiGpztPaZXL4Ha1e1pMWE12R3pgT618 YUbFbAQLaSAa/20lZmqZIIEgFsty6s9AvELaQaRPzD5Bj+dR4pQExunXXBudRhfYb1 WRaGQcW9NV7mw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4YKM1K0DWDz6tw3; Fri, 27 Dec 2024 11:19:32 +0100 (CET) From: Ihor Radchenko To: Joseph Turner Cc: Christian Moe , Org Mode Mailing List , Bohong Huang Subject: Re: Form feed characters break odt export In-Reply-To: <878qs4oyyh.fsf@breatheoutbreathe.in> References: <87ed21hkmi.fsf@breatheoutbreathe.in> <87ikrajoe4.fsf@localhost> <87o711l4u4.fsf@christianmoe.com> <87jzbpgocm.fsf@localhost> <878qs4oyyh.fsf@breatheoutbreathe.in> Date: Fri, 27 Dec 2024 10:21:02 +0000 Message-ID: <87plld5svl.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.00 X-Spam-Score: -4.00 X-Migadu-Queue-Id: E1A2986086 X-Migadu-Scanner: mx10.migadu.com X-TUID: d3jgNl8Lo24u --=-=-= Content-Type: text/plain Joseph Turner writes: > Thanks, Ihor! Tested working on my machine. > > Here's another potential solution to consider, which adds a defcustom to > let the user decide how to handle forbidden characters: > > https://github.com/kjambunathan/org-mode-ox-odt/commit/07fde1e9b7cdda3e3ef8136f5b1d478499dfd780 Good idea! I went even further and used a proper export setting. See the attached 2nd version of the fix. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v2-0001-ox-odt-Avoid-putting-forbidden-characters-into-OD.patch >From de015e4a3b98bc975c2dcd1dfce7adcf77eb537c Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Tue, 24 Dec 2024 15:11:22 +0100 Subject: [PATCH v2] ox-odt: Avoid putting forbidden characters into ODT xml * lisp/ox-odt.el (org-odt-with-forbidden-chars): New export option to control how to handle forbidden XML characters. (org-odt--remove-forbidden): New filter removing/replacing forbidden characters. Reported-by: Joseph Turner Link: https://orgmode.org/list/87o711l4u4.fsf@christianmoe.com --- lisp/ox-odt.el | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index ec81637ef0..635bf38971 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -94,7 +94,8 @@ (org-export-define-backend 'odt . (org-odt--translate-latex-fragments org-odt--translate-description-lists org-odt--translate-list-tables - org-odt--translate-image-links))) + org-odt--translate-image-links)) + (:filter-final-output . org-odt--remove-forbidden)) :menu-entry '(?o "Export to ODT" ((?o "As ODT file" org-odt-export-to-odt) @@ -108,6 +109,7 @@ (org-export-define-backend 'odt (:keywords "KEYWORDS" nil nil space) (:subtitle "SUBTITLE" nil nil parse) ;; Other variables. + (:odt-with-forbidden-chars nil nil org-odt-with-forbidden-chars) (:odt-content-template-file nil nil org-odt-content-template-file) (:odt-display-outline-level nil nil org-odt-display-outline-level) (:odt-fontify-srcblocks nil nil org-odt-fontify-srcblocks) @@ -170,6 +172,14 @@ (defconst org-odt-special-string-regexps ("\\.\\.\\." . "…")) ; hellip "Regular expressions for special string conversion.") +(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})))) + "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) + (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) + ((and (pred stringp) rep) + (prog1 (replace-regexp-in-string org-odt-forbidden-char-re rep text) + (when (match-string 0 text) + (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 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode maintainer, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--