kjambunathan / org-mode-ox-odt

The Authoritative fork of Org mode's ODT exporter
GNU General Public License v3.0
45 stars 9 forks source link

Verse block export bug: superfluous newline at the end of the block #242

Closed nitardus closed 1 year ago

nitardus commented 1 year ago

If I export a verse block with #+begin_verse #+end_verse, there is always a superfluous empty line at the end (immediately before #+end-verse). Looking at your code (8699-8710 of ox-odt.el), this must happen with necessity, since at the end of the block there has to be a newline, which gets converted by the org-odt-verse-block function. Modifiying lines 8703-8706 of your code did the job for me:

;; Add line breaks to each line of verse. (setq contents (replace-regexp-in-string "\(\)?[ \t]*\n" "" (substring contents 0 -1)))

kjambunathan commented 1 year ago

The new line at the end of the verse block has a purpose; it "spaces out" the verse block from the following paragraph. So, if you remove the trailing new line in a verse block, there won't be any space between the verse block and the following paragraph.

I agree that using a line break for spacing is not a good idea. So, I have taken your suggestion, and also updated the `OrgVerse' style.

To get this

Screenshot from 2023-04-27 19-26-49

do this

#+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+options: author:t broken-links:mark c:nil creator:nil
#+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t
#+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t
#+options: timestamp:t title:t toc:nil todo:t |:t
#+title: Verse Block
#+date: <2023-04-27 Thu>
#+author: Jambunathan K
#+email: kjambunathan@gmail.com
#+language: en
#+select_tags: export
#+exclude_tags: noexport
#+creator: Emacs 30.0.50 (Org mode 9.6.1)
#+cite_export:

#+begin_verse
    The woods are lovely, dark and deep,
        But I have promises to keep,
    And miles to go before I sleep,
        And miles to go before I sleep.
#+end_verse

Robert Frost, “Stopping by Woods on a Snowy Evening” from /The Poetry
of Robert Frost,/ edited by Edward Connery Lathem. Copyright 1923, ©
1969 by Henry Holt and Company, Inc., renewed 1951, by Robert
Frost. Reprinted with the permission of Henry Holt and Company, LLC.

Source: //Collected Poems, Prose, & Plays// (Library of America, 1995)

# Add background colour to the verse block

#+ATTR_ODT: :target "extra_styles"
#+begin_src nxml
<style:style style:name="OrgVerse"
             style:parent-style-name="Preformatted_20_Text"
             style:family="paragraph">
  <style:paragraph-properties fo:background-color="#f6f9d4"
                              fo:border="0.06pt solid #000000"
                              fo:margin-bottom="0.21cm"
                              fo:margin-top="0cm"
                              fo:padding="0.049cm"
                              style:shadow="none" />
</style:style>
#+end_src