From 739ddc3b27a5a2f0b05b576f671069c868835a21 Mon Sep 17 00:00:00 2001 From: Vaidheeswaran C Date: Wed, 4 Mar 2015 14:12:49 +0530 Subject: [PATCH] Revert to 8ad20618d1ff574406dc1ad6e998f400 --- lisp/ox-odt.el | 557 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 271 insertions(+), 286 deletions(-) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index 386e89426..eb359a47a 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -1,6 +1,6 @@ ;;; ox-odt.el --- OpenDocument Text Exporter for Org Mode -;; Copyright (C) 2010-2015 Free Software Foundation, Inc. +;; Copyright (C) 2010-2014 Free Software Foundation, Inc. ;; Author: Jambunathan K ;; Keywords: outlines, hypermedia, calendar, wp @@ -99,6 +99,11 @@ '((:odt-styles-file "ODT_STYLES_FILE" nil nil t) ;; Other variables. (:odt-content-template-file nil nil org-odt-content-template-file) + (:odt-convert-capabilities nil nil org-odt-convert-capabilities) + (:odt-convert-process nil nil org-odt-convert-process) + (:odt-convert-processes nil nil org-odt-convert-processes) + (:odt-create-custom-styles-for-srcblocks + nil nil org-odt-create-custom-styles-for-srcblocks) (:odt-display-outline-level nil nil org-odt-display-outline-level) (:odt-fontify-srcblocks nil nil org-odt-fontify-srcblocks) (:odt-format-drawer-function nil nil org-odt-format-drawer-function) @@ -107,6 +112,9 @@ (:odt-inline-formula-rules nil nil org-odt-inline-formula-rules) (:odt-inline-image-rules nil nil org-odt-inline-image-rules) (:odt-pixels-per-inch nil nil org-odt-pixels-per-inch) + (:odt-preferred-output-format nil nil org-odt-preferred-output-format) + (:odt-prettify-xml nil nil org-odt-prettify-xml) + (:odt-schema-dir nil nil org-odt-schema-dir) (:odt-styles-file nil nil org-odt-styles-file) (:odt-table-styles nil nil org-odt-table-styles) (:odt-use-date-fields nil nil org-odt-use-date-fields) @@ -204,7 +212,8 @@ heuristically based on the values of `org-odt-lib-dir' and This directory contains the following XML files - \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These XML files are used as the default values of - `org-odt-styles-file' and `org-odt-content-template-file'. + `org-odt-styles-file' and + `org-odt-content-template-file'. The default value of this variable varies depending on the version of org in use and is initialized from @@ -676,8 +685,7 @@ The default value simply returns the value of CONTENTS." ;;;; Headline -(defcustom org-odt-format-headline-function - 'org-odt-format-headline-default-function +(defcustom org-odt-format-headline-function 'ignore "Function to format headline text. This function will be called with 5 arguments: @@ -689,15 +697,14 @@ TAGS the tags string, separated with colons \(string or nil\). The function result will be used as headline text." :group 'org-export-odt - :version "25.1" - :package-version '(Org . "8.3") + :version "24.4" + :package-version '(Org . "8.0") :type 'function) ;;;; Inlinetasks -(defcustom org-odt-format-inlinetask-function - 'org-odt-format-inlinetask-default-function +(defcustom org-odt-format-inlinetask-function 'ignore "Function called to format an inlinetask in ODT code. The function must accept six parameters: @@ -710,8 +717,8 @@ The function must accept six parameters: The function should return the string to be exported." :group 'org-export-odt - :version "25.1" - :package-version '(Org . "8.3") + :version "24.4" + :package-version '(Org . "8.0") :type 'function) @@ -799,8 +806,8 @@ Use the latter option if you do not want the custom styles to be based on your current display settings. It is necessary that the styles.xml already contains needed styles for colorizing to work. -This variable is effective only if `org-odt-fontify-srcblocks' is -turned on." +This variable is effective only if +`org-odt-fontify-srcblocks' is turned on." :group 'org-export-odt :version "24.1" :type 'boolean) @@ -837,7 +844,8 @@ TABLE-STYLE-NAME is the style associated with the table through TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined -below) that is included in `org-odt-content-template-file'. +below) that is included in +`org-odt-content-template-file'. TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE + \"TableCell\" @@ -1080,20 +1088,13 @@ See `org-odt--build-date-styles' for implementation details." ;;;; Table of Contents -(defun org-odt--format-toc (title entries depth) - "Return a table of contents. -TITLE is the title of the table, as a string, or nil. ENTRIES is -the contents of the table, as a string. DEPTH is an integer -specifying the depth of the table." +(defun org-odt-begin-toc (index-title depth) (concat - " -\n" - (format " " depth) - (and title - (format " - %s -" - title)) + (format " + + + %s +" depth index-title) (let ((levels (number-sequence 1 10))) (mapconcat @@ -1105,21 +1106,23 @@ specifying the depth of the table." - \n" - level level)) levels "")) - " - - " - (and title - (format " - - %s - \n" - title)) - entries - " - -")) + +" level level)) levels "")) + + (format " + + + + + %s + + " index-title))) + +(defun org-odt-end-toc () + (format " + + +")) (defun* org-odt-format-toc-headline (todo todo-type priority text tags @@ -1127,7 +1130,7 @@ specifying the depth of the table." (setq text (concat ;; Section number. - (and section-number (concat section-number ". ")) + (when section-number (concat section-number ". ")) ;; Todo. (when todo (let ((style (if (member todo org-done-keywords) @@ -1154,12 +1157,7 @@ specifying the depth of the table." (format "%s" headline-label text)) -(defun org-odt-toc (depth info &optional scope) - "Build a table of contents. -DEPTH is an integer specifying the depth of the table. INFO is -a plist containing current export properties. Optional argument -SCOPE, when non-nil, defines the scope of the table. Return the -table of contents as a string, or nil." +(defun org-odt-toc (depth info) (assert (wholenump depth)) ;; When a headline is marked as a radio target, as in the example below: ;; @@ -1171,17 +1169,24 @@ table of contents as a string, or nil." ;; /TOC/, as otherwise there will be duplicated anchors one in TOC ;; and one in the document body. ;; - ;; FIXME: Are there any other objects that need to be suppressed + ;; FIXME-1: Currently exported headings are memoized. `org-export.el' + ;; doesn't provide a way to disable memoization. So this doesn't + ;; work. + ;; + ;; FIXME-2: Are there any other objects that need to be suppressed ;; within TOC? - (let* ((headlines (org-export-collect-headlines info depth scope)) + (let* ((title (org-export-translate "Table of Contents" :utf-8 info)) + (headlines (org-export-collect-headlines + info (and (wholenump depth) depth))) (backend (org-export-create-backend - :parent (org-export-backend-name (plist-get info :back-end)) + :parent (org-export-backend-name + (plist-get info :back-end)) :transcoders (mapcar (lambda (type) (cons type (lambda (d c i) c))) (list 'radio-target))))) (when headlines - (org-odt--format-toc - (and (not scope) (org-export-translate "Table of Contents" :utf-8 info)) + (concat + (org-odt-begin-toc title depth) (mapconcat (lambda (headline) (let* ((entry (org-odt-format-headline--wrap @@ -1191,7 +1196,7 @@ table of contents as a string, or nil." (format "\n%s" style entry))) headlines "\n") - depth)))) + (org-odt-end-toc))))) ;;;; Document styles @@ -1379,7 +1384,7 @@ original parsed data. INFO is a plist holding export options." ;; Non-availability of styles.xml is not a critical ;; error. For now, throw an error. (styles-file (or styles-file - (plist-get info :odt-styles-file) + org-odt-styles-file (expand-file-name "OrgOdtStyles.xml" org-odt-styles-dir) (error "org-odt: Missing styles file?")))) @@ -1404,7 +1409,7 @@ original parsed data. INFO is a plist holding export options." (org-odt--zip-extract styles-file "styles.xml" org-odt-zip-dir))))) (t (error (format "Invalid specification of styles.xml file: %S" - (plist-get info :odt-styles-file))))) + org-odt-styles-file)))) ;; create a manifest entry for styles.xml (org-odt-create-manifest-file-entry "text/xml" "styles.xml") @@ -1465,7 +1470,7 @@ original parsed data. INFO is a plist holding export options." '("%Y-%M-%d %a" . "%Y-%M-%d %a %H:%M")))) (with-temp-buffer (insert-file-contents - (or (plist-get info :odt-content-template-file) + (or org-odt-content-template-file (expand-file-name "OrgOdtContentTemplate.xml" org-odt-styles-dir))) ;; Write automatic styles. @@ -1479,7 +1484,7 @@ original parsed data. INFO is a plist holding export options." (when (setq props (or (plist-get props :rel-width) "96")) (insert (format org-odt-table-style-format style-name props)))) ;; - Dump date-styles. - (when (plist-get info :odt-use-date-fields) + (when org-odt-use-date-fields (insert (org-odt--build-date-styles (car custom-time-fmts) "OrgDate1") (org-odt--build-date-styles (cdr custom-time-fmts) @@ -1498,8 +1503,7 @@ original parsed data. INFO is a plist holding export options." (lambda (x) (format "" - (plist-get info :odt-display-outline-level) - (nth 1 x))) + org-odt-display-outline-level (nth 1 x))) org-odt-category-map-alist "\n"))) ;; Position the cursor to document body. (goto-char (point-min)) @@ -1508,8 +1512,7 @@ original parsed data. INFO is a plist holding export options." ;; Preamble - Title, Author, Date etc. (insert - (let* ((title (and (plist-get info :with-title) - (org-export-data (plist-get info :title) info))) + (let* ((title (org-export-data (plist-get info :title) info)) (author (and (plist-get info :with-author) (let ((auth (plist-get info :author))) (and auth (org-export-data auth info))))) @@ -1553,15 +1556,14 @@ original parsed data. INFO is a plist holding export options." (timestamp (and (not (cdr date)) (eq (org-element-type (car date)) 'timestamp) (car date)))) - (when date - (concat - (format "\n%s" - "OrgSubtitle" - (if (and (plist-get info :odt-use-date-fields) timestamp) - (org-odt--format-timestamp (car date)) - (org-export-data date info))) - ;; Separator - ""))))))) + (concat + (format "\n%s" + "OrgSubtitle" + (if (and org-odt-use-date-fields timestamp) + (org-odt--format-timestamp (car date)) + (org-export-data (plist-get info :date) info))) + ;; Separator + "")))))) ;; Table of Contents (let* ((with-toc (plist-get info :with-toc)) (depth (and with-toc (if (wholenump with-toc) @@ -1642,7 +1644,7 @@ channel." CONTENTS holds the contents of the block. INFO is a plist holding contextual information." (let* ((name (org-element-property :drawer-name drawer)) - (output (funcall (plist-get info :odt-format-drawer-function) + (output (funcall org-odt-format-drawer-function name contents))) output)) @@ -1696,7 +1698,7 @@ CONTENTS is nil. INFO is a plist holding contextual information." (defun org-odt-fixed-width (fixed-width contents info) "Transcode a FIXED-WIDTH element from Org to ODT. CONTENTS is nil. INFO is a plist holding contextual information." - (org-odt-do-format-code (org-element-property :value fixed-width) info)) + (org-odt-do-format-code (org-element-property :value fixed-width))) ;;;; Footnote Definition @@ -1741,10 +1743,9 @@ CONTENTS is nil. INFO is a plist holding contextual information." (format "%s" "OrgSuperscript" ","))) ;; Transcode footnote reference. - (let ((n (org-export-get-footnote-number footnote-reference info nil t))) + (let ((n (org-export-get-footnote-number footnote-reference info))) (cond - ((not - (org-export-footnote-first-reference-p footnote-reference info nil t)) + ((not (org-export-footnote-first-reference-p footnote-reference info)) (funcall --format-footnote-reference n)) ;; Inline definitions are secondary strings. ;; Non-inline footnotes definitions are full Org data. @@ -1760,8 +1761,7 @@ CONTENTS is nil. INFO is a plist holding contextual information." :transcoders '((paragraph . (lambda (p c i) (org-odt--format-paragraph - p c i - "Footnote" + p c "Footnote" "OrgFootnoteCenter" "OrgFootnoteQuotations"))))) info)))) @@ -1773,6 +1773,33 @@ CONTENTS is nil. INFO is a plist holding contextual information." ;;;; Headline +(defun* org-odt-format-headline + (todo todo-type priority text tags + &key level section-number headline-label &allow-other-keys) + (concat + ;; Todo. + (when todo + (let ((style (if (member todo org-done-keywords) "OrgDone" "OrgTodo"))) + (format "%s " + style todo))) + (when priority + (let* ((style (format "OrgPriority-%s" priority)) + (priority (format "[#%c]" priority))) + (format "%s " + style priority))) + ;; Title. + text + ;; Tags. + (when tags + (concat + "" + (format "[%s]" + "OrgTags" (mapconcat + (lambda (tag) + (format + "%s" + "OrgTag" tag)) tags " : ")))))) + (defun org-odt-format-headline--wrap (headline backend info &optional format-function &rest extra-keys) @@ -1795,17 +1822,19 @@ INFO is a plist holding contextual information." (org-element-property :title headline) backend info)) (tags (and (plist-get info :with-tags) (org-export-get-tags headline info))) - (headline-label (org-export-get-headline-id headline info)) - (format-function - (if (functionp format-function) format-function - (function* - (lambda (todo todo-type priority text tags - &key level section-number headline-label - &allow-other-keys) - (funcall (plist-get info :odt-format-headline-function) - todo todo-type priority text tags)))))) + (headline-label (concat "sec-" (mapconcat 'number-to-string + headline-number "-"))) + (format-function (cond + ((functionp format-function) format-function) + ((not (eq org-odt-format-headline-function 'ignore)) + (function* + (lambda (todo todo-type priority text tags + &allow-other-keys) + (funcall org-odt-format-headline-function + todo todo-type priority text tags)))) + (t 'org-odt-format-headline)))) (apply format-function - todo todo-type priority text tags + todo todo-type priority text tags :headline-label headline-label :level level :section-number section-number extra-keys))) @@ -1820,9 +1849,10 @@ holding contextual information." (full-text (org-odt-format-headline--wrap headline nil info)) ;; Get level relative to current parsed data. (level (org-export-get-relative-level headline info)) - (numbered (org-export-numbered-headline-p headline info)) ;; Get canonical label for the headline. - (id (org-export-get-headline-id headline info)) + (id (concat "sec-" (mapconcat 'number-to-string + (org-export-get-headline-number + headline info) "-"))) ;; Get user-specified labels for the headline. (extra-ids (list (org-element-property :CUSTOM_ID headline) (org-element-property :ID headline))) @@ -1846,7 +1876,8 @@ holding contextual information." (and (org-export-first-sibling-p headline info) (format "\n" ;; Choose style based on list type. - (if numbered "OrgNumberedList" "OrgBulletedList") + (if (org-export-numbered-headline-p headline info) + "OrgNumberedList" "OrgBulletedList") ;; If top-level list, re-start numbering. Otherwise, ;; continue numbering. (format "text:continue-numbering=\"%s\"" @@ -1873,41 +1904,12 @@ holding contextual information." (t (concat (format - "\n%s" - (format "Heading_20_%s%s" - level (if numbered "" "_unnumbered")) + "\n%s" + (format "Heading_20_%s" level) level - (if numbered "false" "true") (concat extra-targets anchored-title)) contents)))))) -(defun org-odt-format-headline-default-function - (todo todo-type priority text tags) - "Default format function for a headline. -See `org-odt-format-headline-function' for details." - (concat - ;; Todo. - (when todo - (let ((style (if (eq todo-type 'done) "OrgDone" "OrgTodo"))) - (format "%s " style todo))) - (when priority - (let* ((style (format "OrgPriority-%s" priority)) - (priority (format "[#%c]" priority))) - (format "%s " - style priority))) - ;; Title. - text - ;; Tags. - (when tags - (concat - "" - (format "[%s]" - "OrgTags" (mapconcat - (lambda (tag) - (format - "%s" - "OrgTag" tag)) tags " : ")))))) - ;;;; Horizontal Rule @@ -1949,33 +1951,29 @@ contextual information." "Transcode an INLINETASK element from Org to ODT. CONTENTS holds the contents of the block. INFO is a plist holding contextual information." - (let* ((todo - (and (plist-get info :with-todo-keywords) - (let ((todo (org-element-property :todo-keyword inlinetask))) - (and todo (org-export-data todo info))))) - (todo-type (and todo (org-element-property :todo-type inlinetask))) - (priority (and (plist-get info :with-priority) - (org-element-property :priority inlinetask))) - (text (org-export-data (org-element-property :title inlinetask) info)) - (tags (and (plist-get info :with-tags) - (org-export-get-tags inlinetask info)))) - (funcall (plist-get info :odt-format-inlinetask-function) - todo todo-type priority text tags contents))) - -(defun org-odt-format-inlinetask-default-function - (todo todo-type priority name tags contents) - "Default format function for a inlinetasks. -See `org-odt-format-inlinetask-function' for details." - (format "\n%s" - "Text_20_body" - (org-odt--textbox - (concat - (format "\n%s" - "OrgInlineTaskHeading" - (org-odt-format-headline-default-function - todo todo-type priority name tags)) - contents) - nil nil "OrgInlineTaskFrame" " style:rel-width=\"100%\""))) + (cond + ;; If `org-odt-format-inlinetask-function' is not 'ignore, call it + ;; with appropriate arguments. + ((not (eq org-odt-format-inlinetask-function 'ignore)) + (let ((format-function + (function* + (lambda (todo todo-type priority text tags + &key contents &allow-other-keys) + (funcall org-odt-format-inlinetask-function + todo todo-type priority text tags contents))))) + (org-odt-format-headline--wrap + inlinetask nil info format-function :contents contents))) + ;; Otherwise, use a default template. + (t + (format "\n%s" + "Text_20_body" + (org-odt--textbox + (concat + (format "\n%s" + "OrgInlineTaskHeading" + (org-odt-format-headline--wrap inlinetask nil info)) + contents) + nil nil "OrgInlineTaskFrame" " style:rel-width=\"100%\""))))) ;;;; Italic @@ -2019,8 +2017,7 @@ contextual information." (defun org-odt-keyword (keyword contents info) "Transcode a KEYWORD element from Org to ODT. -CONTENTS is nil. INFO is a plist holding contextual -information." +CONTENTS is nil. INFO is a plist holding contextual information." (let ((key (org-element-property :key keyword)) (value (org-element-property :value keyword))) (cond @@ -2029,15 +2026,14 @@ information." ;; FIXME (ignore)) ((string= key "TOC") - (let ((case-fold-search t)) + (let ((value (downcase value))) (cond - ((org-string-match-p "\\" value) - (let ((depth (or (and (string-match "\\<[0-9]+\\>" value) + ((string-match "\\" value) + (let ((depth (or (and (string-match "[0-9]+" value) (string-to-number (match-string 0 value))) - (plist-get info :headline-levels))) - (localp (org-string-match-p "\\" value))) - (org-odt-toc depth info (and localp keyword)))) - ((org-string-match-p "tables\\|figures\\|listings" value) + (plist-get info :with-toc)))) + (when (wholenump depth) (org-odt-toc depth info)))) + ((member value '("tables" "figures" "listings")) ;; FIXME (ignore)))))))) @@ -2058,7 +2054,7 @@ information." CONTENTS is nil. INFO is a plist holding contextual information." (let* ((latex-frag (org-remove-indentation (org-element-property :value latex-environment)))) - (org-odt-do-format-code latex-frag info))) + (org-odt-do-format-code latex-frag))) ;;;; Latex Fragment @@ -2095,7 +2091,7 @@ CONTENTS is nil. INFO is a plist holding contextual information." (let* ((--numbered-parent-headline-at-<=-n (function (lambda (element n info) - (loop for x in (org-element-lineage element) + (loop for x in (org-export-get-genealogy element) thereis (and (eq (org-element-type x) 'headline) (<= (org-export-get-relative-level x info) n) (org-export-numbered-headline-p x info) @@ -2113,9 +2109,7 @@ CONTENTS is nil. INFO is a plist holding contextual information." counter)) info 'first-match))))) (scope (funcall --numbered-parent-headline-at-<=-n - element - (or n (plist-get info :odt-display-outline-level)) - info)) + element (or n org-odt-display-outline-level) info)) (ordinal (funcall --enumerate element scope info predicate)) (tag (concat @@ -2235,8 +2229,8 @@ SHORT-CAPTION are strings." (org-odt-create-manifest-file-entry media-type target-file) target-file)) -(defun org-odt--image-size - (file info &optional user-width user-height scale dpi embed-as) +(defun org-odt--image-size (file &optional user-width + user-height scale dpi embed-as) (let* ((--pixels-to-cms (function (lambda (pixels dpi) (let ((cms-per-inch 2.54) @@ -2248,7 +2242,7 @@ SHORT-CAPTION are strings." (and size-in-pixels (cons (funcall --pixels-to-cms (car size-in-pixels) dpi) (funcall --pixels-to-cms (cdr size-in-pixels) dpi)))))) - (dpi (or dpi (plist-get info :odt-pixels-per-inch))) + (dpi (or dpi org-odt-pixels-per-inch)) (anchor-type (or embed-as "paragraph")) (user-width (and (not scale) user-width)) (user-height (and (not scale) user-height)) @@ -2337,7 +2331,7 @@ used as a communication channel." ;; Handle `:width', `:height' and `:scale' properties. Read ;; them as numbers since we need them for computations. (size (org-odt--image-size - src-expanded info + src-expanded (let ((width (plist-get attr-plist :width))) (and width (read width))) (let ((length (plist-get attr-plist :length))) @@ -2366,7 +2360,7 @@ used as a communication channel." ;; description. This quite useful for debugging. (desc (and replaces (org-element-property :value replaces)))) (org-odt--render-image/formula entity href width height - captions user-frame-params title desc))) + captions user-frame-params title desc))) ;;;; Links :: Math formula @@ -2568,7 +2562,7 @@ used as a communication channel." ;; Link should point to an image file. (lambda (l) (assert (eq (org-element-type l) 'link)) - (org-export-inline-image-p l (plist-get info :odt-inline-image-rules))))) + (org-export-inline-image-p l org-odt-inline-image-rules)))) (defun org-odt--enumerable-latex-image-p (element info) (org-odt--standalone-link-p @@ -2583,7 +2577,7 @@ used as a communication channel." ;; Link should point to an image file. (lambda (l) (assert (eq (org-element-type l) 'link)) - (org-export-inline-image-p l (plist-get info :odt-inline-image-rules))))) + (org-export-inline-image-p l org-odt-inline-image-rules)))) (defun org-odt--enumerable-formula-p (element info) (org-odt--standalone-link-p @@ -2595,7 +2589,7 @@ used as a communication channel." ;; Link should point to a MathML or ODF file. (lambda (l) (assert (eq (org-element-type l) 'link)) - (org-export-inline-image-p l (plist-get info :odt-inline-formula-rules))))) + (org-export-inline-image-p l org-odt-inline-formula-rules)))) (defun org-odt--standalone-link-p (element info &optional paragraph-predicate @@ -2635,12 +2629,11 @@ Return nil, otherwise." (t nil)))))))) (defun org-odt-link--infer-description (destination info) - ;; DESTINATION is a headline or an element (like paragraph, - ;; verse-block etc) to which a "#+NAME: label" can be attached. - - ;; Note that labels that are attached to captioned entities - inline - ;; images, math formulae and tables - get resolved as part of - ;; `org-odt-format-label' and `org-odt--enumerate'. + ;; DESTINATION is a HEADLINE, a "<>" or an element (like + ;; paragraph, verse-block etc) to which a "#+NAME: label" can be + ;; attached. Note that labels that are attached to captioned + ;; entities - inline images, math formulae and tables - get resolved + ;; as part of `org-odt-format-label' and `org-odt--enumerate'. ;; Create a cross-reference to DESTINATION but make best-efforts to ;; create a *meaningful* description. Check item numbers, section @@ -2648,10 +2641,13 @@ Return nil, otherwise." ;; NOTE: Counterpart of `org-export-get-ordinal'. ;; FIXME: Handle footnote-definition footnote-reference? - (let* ((genealogy (org-element-lineage destination)) + (let* ((genealogy (org-export-get-genealogy destination)) (data (reverse genealogy)) (label (case (org-element-type destination) - (headline (org-export-get-headline-id destination info)) + (headline + (format "sec-%s" (mapconcat 'number-to-string + (org-export-get-headline-number + destination info) "-"))) (target (org-element-property :value destination)) (t (error "FIXME: Resolve %S" destination))))) @@ -2693,19 +2689,15 @@ Return nil, otherwise." (format "%s" (org-export-solidify-link-text label) (mapconcat (lambda (n) (if (not n) " " - (concat (number-to-string n) "."))) + (concat (number-to-string n) "."))) item-numbers ""))))) ;; Case 2: Locate a regular and numbered headline in the ;; hierarchy. Display its section number. - (let ((headline - (and - ;; Test if destination is a numbered headline. - (org-export-numbered-headline-p destination info) - (loop for el in (cons destination genealogy) - when (and (eq (org-element-type el) 'headline) - (not (org-export-low-level-p el info)) - (org-export-numbered-headline-p el info)) - return el)))) + (let ((headline (loop for el in (cons destination genealogy) + when (and (eq (org-element-type el) 'headline) + (not (org-export-low-level-p el info)) + (org-export-numbered-headline-p el info)) + return el))) ;; We found one. (when headline (format "%s" @@ -2737,7 +2729,7 @@ INFO is a plist holding contextual information. See ;; Ensure DESC really exists, or set it to nil. (desc (and (not (string= desc "")) desc)) (imagep (org-export-inline-image-p - link (plist-get info :odt-inline-image-rules))) + link org-odt-inline-image-rules)) (path (cond ((member type '("http" "https" "ftp" "mailto")) (concat type ":" raw-path)) @@ -2745,23 +2737,22 @@ INFO is a plist holding contextual information. See (concat "file:" raw-path)) (t raw-path))) ;; Convert & to & for correct XML representation - (path (replace-regexp-in-string "&" "&" path))) + (path (replace-regexp-in-string "&" "&" path)) + protocol) (cond - ;; Link type is handled by a special function. - ((org-export-custom-protocol-maybe link desc 'odt)) ;; Image file. ((and (not desc) (org-export-inline-image-p - link (plist-get info :odt-inline-image-rules))) + link org-odt-inline-image-rules)) (org-odt-link--inline-image link info)) ;; Formula file. ((and (not desc) (org-export-inline-image-p - link (plist-get info :odt-inline-formula-rules))) + link org-odt-inline-formula-rules)) (org-odt-link--inline-formula link info)) ;; Radio target: Transcode target's contents and use them as ;; link's description. ((string= type "radio") (let ((destination (org-export-resolve-radio-link link info))) - (if (not destination) desc + (when destination (format "%s" (org-export-solidify-link-text @@ -2786,9 +2777,11 @@ INFO is a plist holding contextual information. See ;; If there's a description, create a hyperlink. ;; Otherwise, try to provide a meaningful description. (if (not desc) (org-odt-link--infer-description destination info) - (let ((label (or (and (string= type "custom-id") - (org-element-property :CUSTOM_ID destination)) - (org-export-get-headline-id destination info)))) + (let* ((headline-no + (org-export-get-headline-number destination info)) + (label + (format "sec-%s" + (mapconcat 'number-to-string headline-no "-")))) (format "%s" label desc)))) @@ -2796,10 +2789,11 @@ INFO is a plist holding contextual information. See (target ;; If there's a description, create a hyperlink. ;; Otherwise, try to provide a meaningful description. - (let ((label (org-element-property :value destination))) - (format "%s" - (org-export-solidify-link-text label) - (or desc (org-export-get-ordinal destination info))))) + (if (not desc) (org-odt-link--infer-description destination info) + (let ((label (org-element-property :value destination))) + (format "%s" + (org-export-solidify-link-text label) + desc)))) ;; Case 4: Fuzzy link points to some element (e.g., an ;; inline image, a math formula or a table). (otherwise @@ -2829,6 +2823,9 @@ INFO is a plist holding contextual information. See (format "%s" href line-no)))) + ;; Link type is handled by a special function. + ((functionp (setq protocol (nth 2 (assoc type org-link-protocols)))) + (funcall protocol (org-link-unescape path) desc 'odt)) ;; External link with a description part. ((and path desc) (let ((link-contents (org-element-contents link))) @@ -2837,8 +2834,7 @@ INFO is a plist holding contextual information. See (let ((desc-element (car link-contents))) (and (eq (org-element-type desc-element) 'link) (org-export-inline-image-p - desc-element - (plist-get info :odt-inline-image-rules))))) + desc-element org-odt-inline-image-rules)))) ;; Format link as a clickable image. (format "\n\n%s\n" path desc) @@ -2868,44 +2864,33 @@ information." ;;;; Paragraph -(defun org-odt--paragraph-style (paragraph) - "Return style of PARAGRAPH. -Style is a symbol among `quoted', `centered' and nil." - (let ((up paragraph)) - (while (and (setq up (org-element-property :parent up)) - (not (memq (org-element-type up) - '(center-block quote-block section))))) - (case (org-element-type up) - (center-block 'centered) - (quote-block 'quoted)))) - -(defun org-odt--format-paragraph (paragraph contents info default center quote) +(defun org-odt--format-paragraph (paragraph contents default center quote) "Format paragraph according to given styles. PARAGRAPH is a paragraph type element. CONTENTS is the -transcoded contents of that paragraph, as a string. INFO is -a plist used as a communication channel. DEFAULT, CENTER and -QUOTE are, respectively, style to use when paragraph belongs to -no special environment, a center block, or a quote block." - (format "\n%s" - (case (org-odt--paragraph-style paragraph) - (quoted quote) - (centered center) - (otherwise default)) - ;; If PARAGRAPH is a leading paragraph in an item that has - ;; a checkbox, splice checkbox and paragraph contents - ;; together. - (concat (let ((parent (org-element-property :parent paragraph))) - (and (eq (org-element-type parent) 'item) - (not (org-export-get-previous-element paragraph info)) - (org-odt--checkbox parent))) - contents))) +transcoded contents of that paragraph, as a string. DEFAULT, +CENTER and QUOTE are, respectively, style to use when paragraph +belongs to no special environment, a center block, or a quote +block." + (let* ((parent (org-export-get-parent paragraph)) + (parent-type (org-element-type parent)) + (style (case parent-type + (quote-block quote) + (center-block center) + (t default)))) + ;; If this paragraph is a leading paragraph in an item and the + ;; 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)))) + (setq contents (concat (org-odt--checkbox parent) contents))) + (format "\n%s" style contents))) (defun org-odt-paragraph (paragraph contents info) "Transcode a PARAGRAPH element from Org to ODT. CONTENTS is the contents of the paragraph, as a string. INFO is the plist used as a communication channel." (org-odt--format-paragraph - paragraph contents info + paragraph contents (or (org-element-property :style paragraph) "Text_20_body") "OrgCenter" "Quotations")) @@ -3063,7 +3048,7 @@ contextual information." "Transcode a SPECIAL-BLOCK element from Org to ODT. CONTENTS holds the contents of the block. INFO is a plist holding contextual information." - (let ((type (org-element-property :type special-block)) + (let ((type (downcase (org-element-property :type special-block))) (attributes (org-export-read-attribute :attr_odt special-block))) (cond ;; Annotation. @@ -3151,13 +3136,13 @@ and prefix with \"OrgSrc\". For example, (org-no-warnings (htmlfontify-string line)))) (defun org-odt-do-format-code - (code info &optional lang refs retain-labels num-start) + (code &optional lang refs retain-labels num-start) (let* ((lang (or (assoc-default lang org-src-lang-modes) lang)) (lang-mode (and lang (intern (format "%s-mode" lang)))) (code-lines (org-split-string code "\n")) (code-length (length code-lines)) (use-htmlfontify-p (and (functionp lang-mode) - (plist-get info :odt-fontify-srcblocks) + org-odt-fontify-srcblocks (require 'htmlfontify nil t) (fboundp 'htmlfontify-string))) (code (if (not use-htmlfontify-p) code @@ -3212,7 +3197,7 @@ and prefix with \"OrgSrc\". For example, (num-start (case (org-element-property :number-lines element) (continued (org-export-get-loc element info)) (new 0)))) - (org-odt-do-format-code code info lang refs retain-labels num-start))) + (org-odt-do-format-code code lang refs retain-labels num-start))) (defun org-odt-src-block (src-block contents info) "Transcode a SRC-BLOCK element from Org to ODT. @@ -3279,13 +3264,13 @@ contextual information." (let* ((table (org-export-get-parent-table element)) (table-attributes (org-export-read-attribute :attr_odt table)) (table-style (plist-get table-attributes :style))) - (assoc table-style (plist-get info :odt-table-styles)))) + (assoc table-style org-odt-table-styles))) (defun org-odt-get-table-cell-styles (table-cell info) "Retrieve styles applicable to a table cell. R and C are (zero-based) row and column numbers of the table cell. STYLE-SPEC is an entry in `org-odt-table-styles' -applicable to the current table. It is nil if the table is not +applicable to the current table. It is `nil' if the table is not associated with any style attributes. Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME). @@ -3521,7 +3506,7 @@ pertaining to indentation here." (--walk-list-genealogy-and-collect-tags (function (lambda (table info) - (let* ((genealogy (org-element-lineage table)) + (let* ((genealogy (org-export-get-genealogy table)) (list-genealogy (when (eq (org-element-type (car genealogy)) 'item) (loop for el in genealogy @@ -3674,8 +3659,8 @@ information." CONTENTS is nil. INFO is a plist used as a communication channel." (let* ((raw-value (org-element-property :raw-value timestamp)) - (type (org-element-property :type timestamp))) - (if (not (plist-get info :odt-use-date-fields)) + (type (org-element-property :type timestamp))) + (if (not org-odt-use-date-fields) (let ((value (org-odt-plain-text (org-timestamp-translate timestamp) info))) (case (org-element-property :type timestamp) @@ -3711,7 +3696,7 @@ channel." (format "%s" "OrgDiaryTimestamp" (org-odt-plain-text (org-timestamp-translate timestamp) - info))))))) + info))))))) ;;;; Underline @@ -3801,8 +3786,7 @@ contextual information." (file-name-nondirectory input-file)))) (display-msg (case processing-type - ((dvipng imagemagick) - (format "Creating LaTeX Image %d..." count)) + ((dvipng imagemagick) (format "Creating LaTeX Image %d..." count)) (mathml (format "Creating MathML snippet %d..." count)))) ;; Get an Org-style link to PNG image or the MathML ;; file. @@ -3811,48 +3795,49 @@ contextual information." (insert latex-frag) (org-format-latex cache-subdir cache-dir nil display-msg - nil processing-type) + nil nil processing-type) (buffer-substring-no-properties (point-min) (point-max))))) - (if (org-string-match-p "file:\\([^]]*\\)" link) link - (message "LaTeX Conversion failed.") - nil)))) + (if (not (string-match "file:\\([^]]*\\)" link)) + (prog1 nil (message "LaTeX Conversion failed.")) + link)))) (when org-link - ;; Conversion succeeded. Parse above Org-style link to - ;; a `link' object. - (let* ((link - (org-element-map - (org-element-parse-secondary-string org-link '(link)) - 'link #'identity info t)) - (replacement - (case (org-element-type latex-*) - ;; Case 1: LaTeX environment. Mimic - ;; a "standalone image or formula" by - ;; enclosing the `link' in a `paragraph'. - ;; Copy over original attributes, captions to - ;; the enclosing paragraph. - (latex-environment - (org-element-adopt-elements - (list 'paragraph - (list :style "OrgFormula" - :name - (org-element-property :name latex-*) - :caption - (org-element-property :caption latex-*))) - link)) - ;; Case 2: LaTeX fragment. No special action. - (latex-fragment link)))) - ;; Note down the object that link replaces. - (org-element-put-property replacement :replaces - (list (org-element-type latex-*) - (list :value latex-frag))) - ;; Restore blank after initial element or object. - (org-element-put-property - replacement :post-blank - (org-element-property :post-blank latex-*)) - ;; Replace now. - (org-element-set-element latex-* replacement))))) - info nil nil t))) + ;; Conversion succeeded. Parse above Org-style link to a + ;; `link' object. + (let* ((link (car (org-element-map (with-temp-buffer + (org-mode) + (insert org-link) + (org-element-parse-buffer)) + 'link 'identity)))) + ;; Orphan the link. + (org-element-put-property link :parent nil) + (let* ( + (replacement + (case (org-element-type latex-*) + ;; Case 1: LaTeX environment. + ;; Mimic a "standalone image or formula" by + ;; enclosing the `link' in a `paragraph'. + ;; Copy over original attributes, captions to + ;; the enclosing paragraph. + (latex-environment + (org-element-adopt-elements + (list 'paragraph + (list :style "OrgFormula" + :name (org-element-property :name + latex-*) + :caption (org-element-property :caption + latex-*))) + link)) + ;; Case 2: LaTeX fragment. + ;; No special action. + (latex-fragment link)))) + ;; Note down the object that link replaces. + (org-element-put-property replacement :replaces + (list (org-element-type latex-*) + (list :value latex-frag))) + ;; Replace now. + (org-element-set-element latex-* replacement)))))) + info))) tree) -- 2.11.4.GIT