emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Maxim Nikulin <manikulin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Bug: ODT export of Chinese text inserts spaces for line breaks
Date: Sat, 08 Oct 2022 21:14:55 +0800	[thread overview]
Message-ID: <87wn9afods.fsf@localhost> (raw)
In-Reply-To: <sbhnlv$4t1$1@ciao.gmane.io>

[-- Attachment #1: Type: text/plain, Size: 1642 bytes --]

Maxim Nikulin <manikulin@gmail.com> writes:

> On 29/06/2021 10:47, James Harkins wrote:
>> * Test
>> 1本人不想亲自拿到学历学位证书、急于离校者,可书面委托他人代领学历学位证
>> 书,29日起即可离校;2本人想亲自领取学历学位证书者,按学校规定的程序及有关
>> 要求办理离校手续,领取相关证书后离校;
>
>> Exporting to ODT produces the following (body text, omitting titles,
>> headers and such).
>> 
>> 1本人不想亲自拿到学历学位证书、急于离校者,可书面委托他人代领学历学位证 书,29日起即可离校;2本人想亲自领取学历学位证书者,按学校规定的程序及有关 要求办理离校手续,领取相关证书后离校;
>
> Confirmed: newlines are copied to ODT document as is and they appear as 
> spaces in libreoffice. I did not tried HTML since I am unsure if 
> browsers should glue paragraphs with newlines into continuous string 
> without spaces. Maybe it is necessary to add some attributes for proper 
> representation (e.g. "lang"), however "#+LANGUAGE: cn" does not help 
> even though libreoffice considers paragraph as Chinese.

Newlines appearing as spaces is in ODT schema.

> As to splicing lines, I found `fill-delete-newlines' that uses 
> `fill-nospace-between-words-table' besides ?| category to determine 
> whether space should be suppressed while splicing lines. In addition 
> there are some variables to tune behavior.

I am attaching the fix that leverages `fill-region' to handle all the
complexities for us. It is the easiest way and I see no reason to look
deeper.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-odt-Fix-newlines-replaced-by-spaces-in-Han-script.patch --]
[-- Type: text/x-patch, Size: 1833 bytes --]

From 614944ba1ac5502c7648747363674b8d45bfaaf7 Mon Sep 17 00:00:00 2001
Message-Id: <614944ba1ac5502c7648747363674b8d45bfaaf7.1665234699.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sat, 8 Oct 2022 21:08:47 +0800
Subject: [PATCH] ox-odt: Fix newlines replaced by spaces in Han script

* lisp/ox-odt.el (org-odt-plain-text): Use `fill-region' to unfill the
paragraphs with newlines accounting for scripts without spaces between
words.

Reported-by: James Harkins <jamshark70@zoho.com>
Link: https://orgmode.org/list/sbhnlv$4t1$1@ciao.gmane.io
---
 lisp/ox-odt.el | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 208a39d9d..c989d2014 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -2903,9 +2903,20 @@ (defun org-odt-plain-text (text info)
 	(setq output
 	      (replace-regexp-in-string (car pair) (cdr pair) output t nil))))
     ;; Handle break preservation if required.
-    (when (plist-get info :preserve-breaks)
-      (setq output (replace-regexp-in-string
-		    "\\(\\\\\\\\\\)?[ \t]*\n" "<text:line-break/>" output t)))
+    (if (plist-get info :preserve-breaks)
+        (setq output (replace-regexp-in-string
+		      "\\(\\\\\\\\\\)?[ \t]*\n" "<text:line-break/>" output t))
+      ;; OpenDocument schema recognizes newlines as spaces, which may
+      ;; not be desired in scripts that do not separate words with
+      ;; spaces (for example, Han script).  `fill-region' is able to
+      ;; handle such situations.
+      (setq output
+            (with-temp-buffer
+              (insert output)
+              ;; Unfill.
+              (let ((fill-column (point-max)))
+                (fill-region (point-min) (point-max)))
+              (buffer-string))))
     ;; Return value.
     output))
 
-- 
2.35.1


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

  reply	other threads:[~2022-10-08 13:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-29  3:47 Bug: ODT export of Chinese text inserts spaces for line breaks James Harkins
2021-06-29  4:43 ` tumashu
2021-06-29 17:01   ` Bug: " Maxim Nikulin
2021-06-29 18:19     ` Eric Abrahamsen
2021-06-30 12:22       ` Maxim Nikulin
2022-10-08 13:14         ` Ihor Radchenko [this message]
2022-10-21  5:38           ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wn9afods.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).