初稿: 2018-08-09 Thu 09:52
最終更新日: 2018-12-14 Fri 20:44
ホーム | 文書トップ | 目次

org-export-data
org記法のパース

  1: (defun org-export-data (data info)
  2:   "Convert DATA into current back-end format.
  3: 
  4: DATA is a parse tree, an element or an object or a secondary
  5: string.  INFO is a plist holding export options.
  6: 
  7: Return a string."
  8:   (or (gethash data (plist-get info :exported-data))
  9:       ;; Handle broken links according to
 10:       ;; `org-export-with-broken-links'.
 11:       (cl-macrolet
 12:           ((broken-link-handler
 13:             (&rest body)
 14:             `(condition-case err
 15:                  (progn ,@body)
 16:                (org-link-broken
 17:                 (pcase (plist-get info :with-broken-links)
 18:                   (`nil (user-error "Unable to resolve link: %S" (nth 1 err)))
 19:                   (`mark (org-export-data
 20:                           (format "[BROKEN LINK: %s]" (nth 1 err)) info))
 21:                   (_ nil))))))
 22:         (let* ((type (org-element-type data))
 23:                (parent (org-export-get-parent data))
 24:                (results
 25:                 (cond
 26:                  ;; Ignored element/object.
 27:                  ((memq data (plist-get info :ignore-list)) nil)
 28:                  ;; Plain text.
 29:                  ((eq type 'plain-text)
 30:                   (org-export-filter-apply-functions
 31:                    (plist-get info :filter-plain-text)
 32:                    (let ((transcoder (org-export-transcoder data info)))
 33:                      (if transcoder (funcall transcoder data info) data))
 34:                    info))
 35:                  ;; Secondary string.
 36:                  ((not type)
 37:                   (mapconcat (lambda (obj) (org-export-data obj info)) data ""))
 38:                  ;; Element/Object without contents or, as a special
 39:                  ;; case, headline with archive tag and archived trees
 40:                  ;; restricted to title only.
 41:                  ((or (not (org-element-contents data))
 42:                       (and (eq type 'headline)
 43:                            (eq (plist-get info :with-archived-trees) 'headline)
 44:                            (org-element-property :archivedp data)))
 45:                   (let ((transcoder (org-export-transcoder data info)))
 46:                     (or (and (functionp transcoder)
 47:                              (broken-link-handler
 48:                               (funcall transcoder data nil info)))
 49:                         ;; Export snippets never return a nil value so
 50:                         ;; that white spaces following them are never
 51:                         ;; ignored.
 52:                         (and (eq type 'export-snippet) ""))))
 53:                  ;; Element/Object with contents.
 54:                  (t
 55:                   (let ((transcoder (org-export-transcoder data info)))
 56:                     (when transcoder
 57:                       (let* ((greaterp (memq type org-element-greater-elements))
 58:                              (objectp
 59:                               (and (not greaterp)
 60:                                    (memq type org-element-recursive-objects)))
 61:                              (contents
 62:                               (mapconcat
 63:                                (lambda (element) (org-export-data element info))
 64:                                (org-element-contents
 65:                                 (if (or greaterp objectp) data
 66:                                   ;; Elements directly containing
 67:                                   ;; objects must have their indentation
 68:                                   ;; normalized first.
 69:                                   (org-element-normalize-contents
 70:                                    data
 71:                                    ;; When normalizing contents of the
 72:                                    ;; first paragraph in an item or
 73:                                    ;; a footnote definition, ignore
 74:                                    ;; first line's indentation: there is
 75:                                    ;; none and it might be misleading.
 76:                                    (when (eq type 'paragraph)
 77:                                      (and
 78:                                       (eq (car (org-element-contents parent))
 79:                                           data)
 80:                                       (memq (org-element-type parent)
 81:                                             '(footnote-definition item)))))))
 82:                                "")))
 83:                         (broken-link-handler
 84:                          (funcall transcoder data
 85:                                   (if (not greaterp) contents
 86:                                     (org-element-normalize-string contents))
 87:                                   info)))))))))
 88:           ;; Final result will be memoized before being returned.
 89:           (puthash
 90:            data
 91:            (cond
 92:             ((not results) "")
 93:             ((memq type '(org-data plain-text nil)) results)
 94:             ;; Append the same white space between elements or objects
 95:             ;; as in the original buffer, and call appropriate filters.
 96:             (t
 97:              (org-export-filter-apply-functions
 98:               (plist-get info (intern (format ":filter-%s" type)))
 99:               (let ((blank (or (org-element-property :post-blank data) 0)))
100:                 (if (eq (org-element-class data parent) 'object)
101:                     (concat results (make-string blank ?\s))
102:                   (concat (org-element-normalize-string results)
103:                           (make-string blank ?\n))))
104:               info)))
105:            (plist-get info :exported-data))))))

日付: 2018-08-09 Thu 09:52

著者: conao

Created: 2018-12-14 Fri 21:04

Validate