emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [BUG] [ODT] Annotations break paragraphs


From: Nicolas Goaziou
Subject: Re: [O] [BUG] [ODT] Annotations break paragraphs
Date: Mon, 25 Mar 2013 23:15:25 +0100

Hello,

Bastien <address@hidden> writes:

> okay, I reverted my wrong fixes.  I'll let Nicolas have a look.

I attach a patch (hardly tested) for that. Does it work as expected?

> I would not favor a solution that allows more #+begin_ blocks to
> be inlined.

Neither would I. Blocks are containers.

> The proper way to handle this is to introduce a new syntax for
> inlined annotations and to treat them appropriately in exporters.
>
> Since we have both #+begin_src and src_<lang>{...} I'd suggest
> having annotation_{...} or something similar.

I would suggest [annotation:label] or [note:label] a dedicated section
for contents, much like footnotes (aren't they just special footnotes,
after all?). That way, they can be inlined while still being able to
contain paragraphs.

> The LaTeX exporter could use \marginpar{...} and the HTML back-end
> could make them appear when hovering with the mouse on the annotated
> parts (just an idea.)
>
> Maybe we will have to live with the current "regression" for 8.0
> and implement the new syntax for 8.1.  Or for 8.0, if Nicolas thinks
> the change is okay and not too error prone.


Regards,

-- 
Nicolas Goaziou
>From 502e29c49a1d95eb853550f157567ffc328403c6 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <address@hidden>
Date: Mon, 25 Mar 2013 23:07:04 +0100
Subject: [PATCH] ox-odt: Properly handle ANNOTATE special blocks

* lisp/ox-odt.el (org-odt-paragraph, org-odt-special-block): Properly
  handle ANNOTATE special blocks associated to paragraphs.
---
 lisp/ox-odt.el | 59 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 48 insertions(+), 11 deletions(-)

diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 9dd8946..5896d52 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -2888,10 +2888,29 @@ the plist used as a communication channel."
     ;; item has a checkbox, splice the checkbox and paragraph contents
     ;; together.
     (when (and (eq (org-element-type parent) 'item)
-              (eq paragraph (car (org-element-contents parent))))
+              (eq paragraph (car (org-element-contents parent))))
       (setq contents (concat (org-odt--checkbox parent) contents)))
     (assert style)
-    (format "\n<text:p text:style-name=\"%s\">%s</text:p>" style contents)))
+    (concat
+     ;; Open paragraph, unless it is preceded by an annotation with no
+     ;; blank line at its end.
+     (unless (let ((prev (org-export-get-previous-element paragraph info)))
+              (and (eq (org-element-type prev) 'special-block)
+                   (equal (org-element-property :type prev) "ANNOTATION")
+                   (let ((blank (org-element-property :post-blank prev)))
+                     (or (not blank) (zerop blank)))))
+       (format "<text:p text:style-name=\"%s\">" style))
+     ;; Paragraph's contents.
+     contents
+     ;; Close paragraph, unless it is followed by an annotation with
+     ;; no blank line in-between.
+     (unless (and (let ((blank (org-element-property :post-blank paragraph)))
+                   (or (not blank) (zerop blank)))
+                 (let ((next (org-export-get-next-element paragraph info)))
+                   (and (eq (org-element-type next) 'special-block)
+                        (equal (org-element-property :type next)
+                               "ANNOTATION"))))
+       "</text:p>"))))
 
 
 ;;;; Plain List
@@ -3066,15 +3085,33 @@ holding contextual information."
             (date (or (plist-get attributes :date)
                       ;; FIXME: Is `car' right thing to do below?
                       (car (plist-get info :date)))))
-       (format "\n<text:p>%s</text:p>"
-               (format "<office:annotation>\n%s\n</office:annotation>"
-                       (concat
-                        (and author
-                             (format "<dc:creator>%s</dc:creator>" author))
-                        (and date
-                             (format "<dc:date>%s</dc:date>"
-                                     (org-odt--format-timestamp date nil 
'iso-date)))
-                        contents)))))
+       (concat
+        ;; Annotation starts a paragraph when there's no paragraph
+        ;; before it or the paragraph before ends with some blank
+        ;; lines.  In that case, start a new paragraph.
+        (let ((prev (org-export-get-previous-element special-block info)))
+          (unless (and (eq (org-element-type prev) 'paragraph)
+                       (let ((blank (org-element-property :post-blank prev)))
+                         (or (not blank) (zerop blank))))
+            "<text:p text:style-name=\"Text_20_body\">"))
+        (format "<office:annotation>\n%s\n</office:annotation>"
+                (concat
+                 (and author
+                      (format "<dc:creator>%s</dc:creator>" author))
+                 (and date
+                      (format "<dc:date>%s</dc:date>"
+                              (org-odt--format-timestamp date nil 'iso-date)))
+                 contents))
+        ;; Annotation ends a paragraph when it ends with blank lines
+        ;; or when no paragraph follows it.  In that case, end
+        ;; current paragraph.
+        (unless (and (let ((blanks (org-element-property
+                                    :post-blank special-block)))
+                       (or (not blanks) (zerop blanks)))
+                     (eq (org-element-type
+                          (org-export-get-next-element special-block info))
+                         'paragraph))
+          "</text:p>"))))
      ;; Textbox.
      ((string= type "textbox")
       (let ((width (plist-get attributes :width))
-- 
1.8.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]