From: Ihor Radchenko <yantar92@posteo.net>
To: Max Nikulin <manikulin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
Date: Mon, 27 Mar 2023 14:16:08 +0000 [thread overview]
Message-ID: <87lejith3r.fsf@localhost> (raw)
In-Reply-To: <87zg8jwp26.fsf@localhost>
[-- Attachment #1: Type: text/plain, Size: 856 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> Max Nikulin <manikulin@gmail.com> writes:
>
>>> [previous object <max(n1,n2) spaces>]
>>
>> Yes, you do.
>>
>> I expected some complications due to newline characters (not line break
>> markup objects), but they are not included in :post-blank and
>> represented as "\n" string objects.
>
> Newlines are tricky. They may or may not be significant.
> For example, in CJK paragraphs, newlines are to be stripped.
>
> I think that a reasonable thing to do could be not adding newlines if
> the previous object is a plain string ending with a newline.
I think that using max(n1,n2) is an overkill. There is no reason to
alter existing spaces before, if any.
I am attaching tentative patch that simply keeps spaces, but if and only
if the previous object does not end with whitespace (including newline).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-export-prune-tree-Ensure-spaces-when-removing-ob.patch --]
[-- Type: text/x-patch, Size: 3359 bytes --]
From 656c32d075d939aa69bc315bc91515930680377c Mon Sep 17 00:00:00 2001
Message-Id: <656c32d075d939aa69bc315bc91515930680377c.1679926405.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Mon, 27 Mar 2023 16:11:32 +0200
Subject: [PATCH] org-export--prune-tree: Ensure spaces when removing objects
* lisp/ox.el (org-export--prune-tree): If the removed object has
trailing spaces and previous object does not have, keep the trailing
spaces.
* etc/ORG-NEWS (Blank lines after removed objects are not retained
during export): Document the change.
Reported-by: Andrea Lazzarini <andrea.lazzarini1@gmail.com>
Link: https://orgmode.org/list/87o7p7z9k3.fsf@localhost
---
etc/ORG-NEWS | 21 +++++++++++++++++++++
lisp/ox.el | 19 ++++++++++++++++++-
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index ac233a986..caf140279 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -145,6 +145,27 @@ execution completes. The new ~:async~ header allows users to continue
editing with Emacs while a ~:session~ block executes.
** Miscellaneous
+*** Blank lines after removed objects are not retained during export
+
+When certain objects in Org document are to be excluded from export,
+spaces after these objects were previously removed as well.
+
+For example, if ~org-export-with-footnotes~ is set to nil, the footnote in
+
+: Pellentesque dapibus suscipit ligula.[fn:1] Donec posuere augue in quam.
+
+would be removed, leading to the following exported ASCII document
+
+: Pellentesque dapibus suscipit ligula.Donec posuere augue in quam.
+
+This is because spaces after footnote (and other markup) are
+considered a part of the preceding AST object in Org.
+
+Now, unless there is a whitespace before an object to be removed,
+spaces are preserved during export:
+
+: Pellentesque dapibus suscipit ligula. Donec posuere augue in quam.
+
*** Remove undocumented ~:target~ header parameter in ~ob-clojure~
The ~:target~ header was only used internally to distinguish
diff --git a/lisp/ox.el b/lisp/ox.el
index f9fc9a99b..206f0536d 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -2752,7 +2752,24 @@ (defun org-export--prune-tree (data info)
(let ((type (org-element-type data)))
(if (org-export--skip-p data info selected excluded)
(if (memq type '(table-cell table-row)) (push data ignore)
- (org-element-extract-element data))
+ (let ((post-blank (org-element-property :post-blank data)))
+ (if (or (not post-blank) (zerop post-blank)
+ (eq 'element (org-element-class data)))
+ (org-element-extract-element data)
+ ;; Keep spaces in place of removed
+ ;; element, if necessary.
+ ;; Example: "Foo.[10%] Bar" would become
+ ;; "Foo.Bar" if we do not keep spaces.
+ (let ((previous (org-export-get-previous-element data info)))
+ (if (or (not previous)
+ (pcase (org-element-type previous)
+ (`plain-text
+ (string-match-p
+ (rx whitespace eos) previous))
+ (_ (org-element-property :post-blank previous))))
+ ;; Previous object ends with whitespace already.
+ (org-element-extract-element data)
+ (org-element-set-element data (make-string post-blank ?\s)))))))
(if (and (eq type 'headline)
(eq (plist-get info :with-archived-trees)
'headline)
--
2.39.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>
next prev parent reply other threads:[~2023-03-27 14:15 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-03 10:07 [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)] Andrea Lazzarini
2023-03-03 14:44 ` Max Nikulin
2023-03-03 15:47 ` Ihor Radchenko
2023-03-03 16:47 ` Max Nikulin
2023-03-04 15:43 ` Andrea Lazzarini
2023-03-05 12:06 ` Ihor Radchenko
2023-03-05 12:32 ` Andrea Lazzarini
2023-03-05 12:42 ` Ihor Radchenko
2023-03-05 12:54 ` Andrea Lazzarini
2023-03-05 13:01 ` Ihor Radchenko
2023-03-06 12:18 ` Max Nikulin
2023-03-07 13:59 ` Ihor Radchenko
2023-03-08 15:14 ` Max Nikulin
2023-03-09 12:43 ` Ihor Radchenko
2023-03-09 15:04 ` Max Nikulin
2023-03-10 12:08 ` Ihor Radchenko
2023-03-10 14:03 ` Max Nikulin
2023-03-11 10:38 ` Ihor Radchenko
2023-03-13 15:17 ` Max Nikulin
2023-03-14 12:19 ` Ihor Radchenko
2023-03-27 14:16 ` Ihor Radchenko [this message]
2023-04-14 11:47 ` Ihor Radchenko
2024-04-24 16:07 ` Max Nikulin
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=87lejith3r.fsf@localhost \
--to=yantar92@posteo.net \
--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).