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 SLBPOpcRb2ekPgEAe85BDQ:P1 (envelope-from ) for ; Fri, 27 Dec 2024 20:44:08 +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 SLBPOpcRb2ekPgEAe85BDQ (envelope-from ) for ; Fri, 27 Dec 2024 21:44:08 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=breatheoutbreathe.in header.s=key1 header.b=BXnOt1Us; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=quarantine) header.from=breatheoutbreathe.in ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1735332247; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=j7mYwK9XVkM9AcmFCniaL2jSajiS9OF+9SZ17QIu4XA=; b=IjJuxDg05L4EuIzhRdd8rnn5NI71BO3Rb95IrVJwz0e4rhpZtzG2ZKNmKydn/aaC2Z5xtm GE+9U4ogwcZwl+a3YZcxjAKG629/YJaV82GpT3RNSnpyNQmgKz0tr/yxoEjc55bpTWnRig GNGdq4ONba1l6pK88dQHzatHck1n25HOhE6F3dNgg5bX3wFZSxpk4L3YNOlu2VHKIqzQJF 9/tc9NGJX2KBBmZcSFFpXRG10OwdL+gUWI7l1t9YUXMst8sduwfRSKPrKRMZqfEXFyfD+y qspxjmn2XW3yoimzh8Juw3+vzqWMJ9Xj1r9TxpguqLPvmTW3eF3ZCpNYiGJnow== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=breatheoutbreathe.in header.s=key1 header.b=BXnOt1Us; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=quarantine) header.from=breatheoutbreathe.in ARC-Seal: i=1; s=key1; d=yhetil.org; t=1735332247; a=rsa-sha256; cv=none; b=p1TCv5r1uQed9riw2HIcb1MhmQty4DSouOUQ/FESZk0/P2bdbU5AGTpUWLP1qTvubOMSPj BEofiDL7LdmOI97Z1a0KSc+33IyeTQfa1io+++FzcTOx5pySj2ITRmXaV57M7bB07PKWop 0yJqolpBqgiVACU7tWeAFjYJo7k5QH0khzBX8nw5in38FdbPjmllDier0PF8QtaMyY8v0A BoXLIf9xKbglTrNrjG9x2Jql5SQ2u/8xG533QRtK3czC63FJpnAr12Sh8tp4eOHRGU7/no Ldg4acLruSTy1x2/7I7G0chVkWQm/GSAGfbYlOWqJW0xdTdplH3AFPl2cJIQEQ== 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 B0198864E3 for ; Fri, 27 Dec 2024 21:44:07 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tRHB2-0001xr-5Z; Fri, 27 Dec 2024 15:43:21 -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 1tRHAn-0001uf-41 for emacs-orgmode@gnu.org; Fri, 27 Dec 2024 15:43:05 -0500 Received: from out-170.mta1.migadu.com ([2001:41d0:203:375::aa]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tRHAj-0007o3-Cw for emacs-orgmode@gnu.org; Fri, 27 Dec 2024 15:43:04 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1735332174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=j7mYwK9XVkM9AcmFCniaL2jSajiS9OF+9SZ17QIu4XA=; b=BXnOt1Us+TY4jep2ArrHP6Q92u8nh36j6zCXzH5t5FpEjOZO8SwCLeX08ApG21c3VDZDN7 5PRhGAko0823rNXlx7ps8IcOJFsOvhdDuceZpEjbWoS7FCo/diR1/webpBzz7cqSvTRlJR HE7DbraA6WWdWe9aYMyH8bSS8TmzmXw= From: Joseph Turner To: Ihor Radchenko Cc: Christian Moe , Org Mode Mailing List , Bohong Huang Subject: Re: Form feed characters break odt export In-Reply-To: <87plld5svl.fsf@localhost> (Ihor Radchenko's message of "Fri, 27 Dec 2024 10:21:02 +0000") References: <87ed21hkmi.fsf@breatheoutbreathe.in> <87ikrajoe4.fsf@localhost> <87o711l4u4.fsf@christianmoe.com> <87jzbpgocm.fsf@localhost> <878qs4oyyh.fsf@breatheoutbreathe.in> <87plld5svl.fsf@localhost> Date: Fri, 27 Dec 2024 12:42:48 -0800 Message-ID: <87jzbk503b.fsf@breatheoutbreathe.in> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2001:41d0:203:375::aa; envelope-from=joseph@breatheoutbreathe.in; helo=out-170.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-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: -9.43 X-Spam-Score: -9.43 X-Migadu-Queue-Id: B0198864E3 X-Migadu-Scanner: mx10.migadu.com X-TUID: WDdNOCXAodIX --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-odt-Avoid-putting-forbidden-characters-into-ODT-x.patch >From ce506caa0bffbd243a2aba384f75f7aaac7fdc4b Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Fri, 27 Dec 2024 10:21:02 +0000 Subject: [PATCH] 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. Co-authored-by: Joseph Turner Link: https://orgmode.org/list/87o711l4u4.fsf@christianmoe.com --- lisp/ox-odt.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index ec81637ef..960bab286 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 left as-is. +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 "Leave forbidden characters as-is" t) + (const :tag "Err when forbidden characters encountered" nil) + (string :tag "Replacement string"))) ;;;; Debugging @@ -2892,6 +2915,32 @@ (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-exhaustive (plist-get info :odt-with-forbidden-chars) + ((and (pred stringp) rep) + (let ((replacements (make-hash-table :test 'equal))) + (with-temp-buffer + (insert text) + (goto-char (point-min)) + (while (re-search-forward org-odt-forbidden-char-re nil t) + (cl-incf (gethash (match-string 0) replacements 0)) + (replace-match rep)) + (cl-loop for forbidden being the hash-keys of replacements + using (hash-values count) + do (display-warning + '(ox-odt ox-odt-with-forbidden-chars) + (format "Replaced forbidden character '%s' with '%s' %d times" + forbidden rep count))) + (buffer-string)))) + (`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)) + ('t 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.46.0 --=-=-= Content-Type: text/plain Thank you!! Joseph --=-=-=--