* [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly
@ 2017-02-28 19:08 Marc Ihm
2017-03-01 13:51 ` Nicolas Goaziou
0 siblings, 1 reply; 8+ messages in thread
From: Marc Ihm @ 2017-02-28 19:08 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 503 bytes --]
Hello,
attached please find a patch for contrib/ox-confluence.el (authored by
Sébastien Delafond); the patch simply translates and fixes some selected
enhancements from ox-confluence-en.el (authored by Correl Roush).
As a result ox-confluence.el encodes square brackets in checkboxes or
inactive timestamps, so that they no longer collide with the native
link-syntax of atlassian confluence.
It would be great, if someone could review and apply this patch if
appropriate.
Best regards,
Marc Ihm
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fix handling of square brackets --]
[-- Type: text/x-patch, Size: 3773 bytes --]
--- a/contrib/lisp/ox-confluence.el 2017-02-28 19:52:25.707036600 +0100
+++ b/contrib/lisp/ox-confluence.el 2017-02-28 19:52:42.225721900 +0100
@@ -38,6 +38,7 @@
;; Define the backend itself
(org-export-define-derived-backend 'confluence 'ascii
+ :filters-alist '((:filter-final-output . org-confluence-fix-timestamps))
:translate-alist '((bold . org-confluence-bold)
(code . org-confluence-code)
(example-block . org-confluence-example-block)
@@ -84,14 +85,23 @@
(defun org-confluence-item (item contents info)
(let* ((plain-list (org-export-get-parent item))
(type (org-element-property :type plain-list))
- (bullet (if (eq type 'ordered) ?\# ?\-)))
- (concat (make-string (1+ (org-confluence--li-depth item)) bullet)
- " "
- (if (eq type 'descriptive)
- (concat "*"
- (org-export-data (org-element-property :tag item) info)
- "* - "))
- (org-trim contents))))
+ (depth (1+ (org-confluence--li-depth item)))
+ (checkbox-possibly (cl-case (org-element-property :checkbox item)
+ (on "*{{(X)}}* ")
+ (off "*{{( )}}* ")
+ (trans "*{{(-)}}* "))))
+ (cl-case plain-list
+ (descriptive
+ (concat (make-string depth ?-) " " checkbox-possibly
+ (org-export-data (org-element-property :tag item) info) ": "
+ (org-trim contents)))
+ (ordered
+ (concat (make-string depth ?#) " " checkbox-possibly
+ (org-trim contents)))
+ (t
+ (concat (make-string depth ?-)
+ " " checkbox-possibly
+ (org-trim contents))))))
(defun org-confluence-fixed-width (fixed-width contents info)
(org-confluence--block
@@ -106,12 +116,18 @@
(format "\{\{%s\}\}" (org-element-property :value code)))
(defun org-confluence-headline (headline contents info)
- (let ((low-level-rank (org-export-low-level-p headline info))
- (text (org-export-data (org-element-property :title headline)
- info))
- (level (org-export-get-relative-level headline info)))
- ;; Else: Standard headline.
- (format "h%s. %s\n%s" level text
+ (let* ((low-level-rank (org-export-low-level-p headline info))
+ (text (org-export-data (org-element-property :title headline)
+ info))
+ (todo (org-export-data (org-element-property :todo-keyword headline)
+ info))
+ (level (org-export-get-relative-level headline info))
+ (todo-text (if (or (not org-export-with-todo-keywords)
+ (string= todo ""))
+ ""
+ (format "*{{%s}}* " todo))))
+
+ (format "h%s. %s%s\n%s" level todo-text text
(if (org-string-nw-p contents) contents
""))))
@@ -167,7 +183,7 @@
(concat
(when (org-export-table-row-starts-header-p table-row info)
"|")
- contents "|")))
+ " " contents " |")))
(defun org-confluence-template (contents info)
(let ((depth (plist-get info :with-toc)))
@@ -199,6 +215,23 @@
(setq item (org-export-get-parent item)))
depth))
+;; Define output filter
+(defun org-confluence-fix-timestamps (text back-end info)
+ "Mask brackets of timestamps in final output, so that
+ confluence does not misinterpret them as links."
+ (with-temp-buffer
+ (insert text)
+ (goto-char (point-min))
+ (while (search-forward-regexp org-ts-regexp-both nil t))
+ (goto-char (match-beginning 0))
+ (when (string= (char-to-string (following-char)) "[")
+ (delete-char 1)
+ (insert "(")
+ (goto-char (match-end 0))
+ (delete-char -1)
+ (insert ")"))
+ (buffer-substring (point-min) (point-max))))
+
;; main interactive entrypoint
(defun org-confluence-export-as-confluence
(&optional async subtreep visible-only body-only ext-plist)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly
2017-02-28 19:08 [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly Marc Ihm
@ 2017-03-01 13:51 ` Nicolas Goaziou
2017-03-01 13:54 ` Nicolas Goaziou
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2017-03-01 13:51 UTC (permalink / raw)
To: Marc Ihm; +Cc: emacs-orgmode
Hello,
Marc Ihm <marc@ihm.name> writes:
> attached please find a patch for contrib/ox-confluence.el (authored by
> Sébastien Delafond); the patch simply translates and fixes some selected
> enhancements from ox-confluence-en.el (authored by Correl Roush).
>
> As a result ox-confluence.el encodes square brackets in checkboxes or
> inactive timestamps, so that they no longer collide with the native
> link-syntax of atlassian confluence.
>
> It would be great, if someone could review and apply this patch if
> appropriate.
Thank you. Comments follow.
> + :filters-alist '((:filter-final-output . org-confluence-fix-timestamps))
Why do you use a final filter? It is a pretty gross tool, couldn't you
simply generate the correct output from the plain-list or item
translator?
> + (cl-case plain-list
> + (descriptive
> + (concat (make-string depth ?-) " " checkbox-possibly
> + (org-export-data (org-element-property :tag item) info) ": "
> + (org-trim contents)))
> + (ordered
> + (concat (make-string depth ?#) " " checkbox-possibly
> + (org-trim contents)))
> + (t
> + (concat (make-string depth ?-)
> + " " checkbox-possibly
> + (org-trim contents))))))
Nitpick: I think the code above could be de-duplicated.
> (when (org-export-table-row-starts-header-p table-row info)
> "|")
> - contents "|")))
> + " " contents " |")))
This doesn't seem related to the description of the problem in your
message, does it?
> (defun org-confluence-template (contents info)
> (let ((depth (plist-get info :with-toc)))
> @@ -199,6 +215,23 @@
> (setq item (org-export-get-parent item)))
> depth))
>
> +;; Define output filter
> +(defun org-confluence-fix-timestamps (text back-end info)
> + "Mask brackets of timestamps in final output, so that
> + confluence does not misinterpret them as links."
> + (with-temp-buffer
> + (insert text)
> + (goto-char (point-min))
> + (while (search-forward-regexp org-ts-regexp-both nil t))
> + (goto-char (match-beginning 0))
> + (when (string= (char-to-string (following-char)) "[")
> + (delete-char 1)
> + (insert "(")
> + (goto-char (match-end 0))
> + (delete-char -1)
> + (insert ")"))
> + (buffer-substring (point-min) (point-max))))
See above.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly
2017-03-01 13:51 ` Nicolas Goaziou
@ 2017-03-01 13:54 ` Nicolas Goaziou
2017-03-01 20:48 ` Marc Ihm
2017-03-02 19:33 ` Marc Ihm
0 siblings, 2 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2017-03-01 13:54 UTC (permalink / raw)
To: Marc Ihm; +Cc: emacs-orgmode
Correcting myselfè
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>> + :filters-alist '((:filter-final-output . org-confluence-fix-timestamps))
>
> Why do you use a final filter? It is a pretty gross tool, couldn't you
> simply generate the correct output from the plain-list or item
> translator?
I meant timestamp translator.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly
2017-03-01 13:54 ` Nicolas Goaziou
@ 2017-03-01 20:48 ` Marc Ihm
2017-03-02 19:33 ` Marc Ihm
1 sibling, 0 replies; 8+ messages in thread
From: Marc Ihm @ 2017-03-01 20:48 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Correcting myselfè
>
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>>> + :filters-alist '((:filter-final-output . org-confluence-fix-timestamps))
>>
>> Why do you use a final filter? It is a pretty gross tool, couldn't you
>> simply generate the correct output from the plain-list or item
>> translator?
>
> I meant timestamp translator.
Wow, didn't know there are already provisions for handling timestamps
specially ! Will adopt my patch.
Thanx for the hint !
Marc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly
2017-03-01 13:54 ` Nicolas Goaziou
2017-03-01 20:48 ` Marc Ihm
@ 2017-03-02 19:33 ` Marc Ihm
2017-03-02 21:16 ` Nicolas Goaziou
1 sibling, 1 reply; 8+ messages in thread
From: Marc Ihm @ 2017-03-02 19:33 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 524 bytes --]
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Correcting myselfè
>
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>>> + :filters-alist '((:filter-final-output . org-confluence-fix-timestamps))
>>
>> Why do you use a final filter? It is a pretty gross tool, couldn't you
>> simply generate the correct output from the plain-list or item
>> translator?
>
> I meant timestamp translator.
Hi,
this is a corrected patch, which handles timestamps in a more canoncial
way.
Best regards
Marc
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch for ox-confluence.el --]
[-- Type: text/x-patch, Size: 3455 bytes --]
--- a/contrib/lisp/ox-confluence.el 2017-03-02 20:10:19.645053100 +0100
+++ b/contrib/lisp/ox-confluence.el 2017-03-02 20:14:57.963701300 +0100
@@ -58,6 +58,7 @@
(table-cell . org-confluence-table-cell)
(table-row . org-confluence-table-row)
(template . org-confluence-template)
+ (timestamp . org-confluence-timestamp)
(underline . org-confluence-underline)
(verbatim . org-confluence-verbatim)))
@@ -81,17 +82,34 @@
(defun org-confluence-italic (italic contents info)
(format "_%s_" contents))
+(defun org-confluence-timestamp (timestamp contents info)
+ "Transcode a TIMESTAMP object from Org to Confluence.
+CONTENTS and INFO are ignored."
+ (let ((translated (org-timestamp-translate timestamp)))
+ (if (string-prefix-p "[" translated)
+ (concat "(" (substring translated 1 -1) ")")
+ translated)))
+
(defun org-confluence-item (item contents info)
(let* ((plain-list (org-export-get-parent item))
(type (org-element-property :type plain-list))
- (bullet (if (eq type 'ordered) ?\# ?\-)))
- (concat (make-string (1+ (org-confluence--li-depth item)) bullet)
- " "
- (if (eq type 'descriptive)
- (concat "*"
- (org-export-data (org-element-property :tag item) info)
- "* - "))
- (org-trim contents))))
+ (depth (1+ (org-confluence--li-depth item)))
+ (checkbox-possibly (cl-case (org-element-property :checkbox item)
+ (on "*{{(X)}}* ")
+ (off "*{{( )}}* ")
+ (trans "*{{(\\-)}}* "))))
+ (cl-case plain-list
+ (descriptive
+ (concat (make-string depth ?-) " " checkbox-possibly
+ (org-export-data (org-element-property :tag item) info) ": "
+ (org-trim contents)))
+ (ordered
+ (concat (make-string depth ?#) " " checkbox-possibly
+ (org-trim contents)))
+ (t
+ (concat (make-string depth ?-)
+ " " checkbox-possibly
+ (org-trim contents))))))
(defun org-confluence-fixed-width (fixed-width contents info)
(org-confluence--block
@@ -106,12 +124,18 @@
(format "\{\{%s\}\}" (org-element-property :value code)))
(defun org-confluence-headline (headline contents info)
- (let ((low-level-rank (org-export-low-level-p headline info))
- (text (org-export-data (org-element-property :title headline)
- info))
- (level (org-export-get-relative-level headline info)))
- ;; Else: Standard headline.
- (format "h%s. %s\n%s" level text
+ (let* ((low-level-rank (org-export-low-level-p headline info))
+ (text (org-export-data (org-element-property :title headline)
+ info))
+ (todo (org-export-data (org-element-property :todo-keyword headline)
+ info))
+ (level (org-export-get-relative-level headline info))
+ (todo-text (if (or (not (plist-get info :with-todo-keywords))
+ (string= todo ""))
+ ""
+ (format "*{{%s}}* " todo))))
+
+ (format "h%s. %s%s\n%s" level todo-text text
(if (org-string-nw-p contents) contents
""))))
@@ -167,7 +191,7 @@
(concat
(when (org-export-table-row-starts-header-p table-row info)
"|")
- contents "|")))
+ " " contents " |")))
(defun org-confluence-template (contents info)
(let ((depth (plist-get info :with-toc)))
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly
2017-03-02 19:33 ` Marc Ihm
@ 2017-03-02 21:16 ` Nicolas Goaziou
2017-03-03 20:50 ` Marc Ihm
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2017-03-02 21:16 UTC (permalink / raw)
To: Marc Ihm; +Cc: emacs-orgmode
Hello,
Marc Ihm <marc@ihm.name> writes:
> this is a corrected patch, which handles timestamps in a more canoncial
> way.
Great. Thank you.
It looks good. Could you provide a commit message?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly
2017-03-02 21:16 ` Nicolas Goaziou
@ 2017-03-03 20:50 ` Marc Ihm
2017-03-05 17:41 ` Nicolas Goaziou
0 siblings, 1 reply; 8+ messages in thread
From: Marc Ihm @ 2017-03-03 20:50 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
> It looks good. Could you provide a commit message?
>
Yes, of course, albeit a bit lengthy:
Fix handling of square brackets from timestamps and checkboxes; avoid
invalid confluence markup for empty table headers.
Best regards
Marc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly
2017-03-03 20:50 ` Marc Ihm
@ 2017-03-05 17:41 ` Nicolas Goaziou
0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2017-03-05 17:41 UTC (permalink / raw)
To: Marc Ihm; +Cc: emacs-orgmode
Hello,
Marc Ihm <marc@ihm.name> writes:
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>>
>> It looks good. Could you provide a commit message?
>>
>
> Yes, of course, albeit a bit lengthy:
>
> Fix handling of square brackets from timestamps and checkboxes; avoid
> invalid confluence markup for empty table headers.
Applied. Thank you.
Regards,
--
Nicolas Goaziou 0x80A93738
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-03-05 17:41 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-28 19:08 [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly Marc Ihm
2017-03-01 13:51 ` Nicolas Goaziou
2017-03-01 13:54 ` Nicolas Goaziou
2017-03-01 20:48 ` Marc Ihm
2017-03-02 19:33 ` Marc Ihm
2017-03-02 21:16 ` Nicolas Goaziou
2017-03-03 20:50 ` Marc Ihm
2017-03-05 17:41 ` Nicolas Goaziou
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.