From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marc Ihm Subject: [PATCH] ox-confluence.el: Handle checkboxes and inactive timestamps correctly Date: Tue, 28 Feb 2017 20:08:07 +0100 Message-ID: <8660ju2kx4.fsf@ihm.name> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cin8N-0002r5-Qa for emacs-orgmode@gnu.org; Tue, 28 Feb 2017 14:08:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cin8I-0007N1-RD for emacs-orgmode@gnu.org; Tue, 28 Feb 2017 14:08:27 -0500 Received: from [195.159.176.226] (port=59885 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cin8I-0007Mq-LD for emacs-orgmode@gnu.org; Tue, 28 Feb 2017 14:08:22 -0500 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cin85-0003S8-NW for emacs-orgmode@gnu.org; Tue, 28 Feb 2017 20:08:09 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=ox-confluence.patch Content-Transfer-Encoding: 8bit Content-Description: fix handling of square brackets --- 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) --=-=-=--