-
Notifications
You must be signed in to change notification settings - Fork 2
/
ox-pollen.el
145 lines (132 loc) · 6.29 KB
/
ox-pollen.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
;;; ox-pollen.el -*- lexical-binding: t; -*-
;; (org-export-define-derived-backend 'pollen 'man
;; :translate-alist
;; '((bold . org-export-pollen-bold)
;; (code . org-export-pollen-code)
;; (headline . org-export-pollen-headline)
;; (italic . org-export-pollen-italic)
;; (plain-text . (lambda (content _)
;; content)) ))
(defmacro org-export-pollen-make-generic (name)
`(lambda (_ contents _info)
(format "◊%s{%s}" ,name contents)))
(org-export-pollen-make-generic "paragraph")
(org-export-define-backend 'pollen
`((bold . ,(org-export-pollen-make-generic "bold"))
(center-block . (lambda (_ contents _)
(format "◊center{%s}" contents)))
;; (clock)
;; (code)
(dynamic-block . ,(org-export-pollen-make-generic "dynamic-block"))
(entity . ,(org-export-pollen-make-generic "entity"))
(example-block . (lambda (example-block _contents info)
"◊example-block{%s}" (org-export-format-code-default example-block info)))
;; (export-block)
;; (export-snippet)
(fixed-width . ,(org-export-pollen-make-generic "fixed-width"))
(footnote-reference . org-export-pollen-footnote-reference)
(headline . org-export-pollen-headline)
(horizontal-rule . (lambda (_ _ _) "◊|horizontal-rule|"))
(inline-src-block . org-export-pollen-inline-src-block)
;; (inline-task)
;; (inner-template . org-ascii-inner-template)
(italic . ,(org-export-pollen-make-generic "italic"))
;; item
(keyword . org-export-pollen-keyword)
;; latex-environment
;; latex-fragment
(line-break . (lambda (&rest) "◊|line-break|"))
(link . org-export-pollen-link)
(node-property . org-org-export-node-property)
(paragraph . (lambda (_paragraph contents _info)
(format "◊p{%s}" contents)))
;; plain list
(plain-text . (lambda (content _)
content))
;; planning
(property-drawer . org-export-pollen-property-drawer)
(quote-block . ,(org-export-pollen-make-generic "quote-block"))
;; radio target
;; (section . ,(org-export-pollen-make-generic "section"))
(section . (lambda (_section contents _info) contents))
(special-block (lambda (_special-block contents _info) contents))
(statistics-cookie . org-export-pollen-statistics-cookie)
(strike-through . ,(org-export-pollen-make-generic "strike-through"))
(subscript . ,(org-export-pollen-make-generic "subscript"))
(superscript . ,(org-export-pollen-make-generic "superscript"))
(src-block . org-export-pollen-code)
;; table
;; table-cell
;; table-row
(target . org-export-pollen-target)
(timestamp . (lambda (timestamp _contents _info)
"◊timestamp{%s}" timestamp))
(template . (lambda (contents info)
(format "#lang pollen\n%s" contents)))
(underline . ,(org-export-pollen-make-generic "underline"))
(verbatim . ,(org-export-pollen-make-generic "verbatim"))
(verse-block . ,(org-export-pollen-make-generic "verse-block"))
:menu-entry
'(?x "Export to Pollen"
((?P "As pollen buffer"
(lambda (a s v b)
(org-export-to-buffer 'pollen "*pollen buffer exports*")))))))
(defun org-export-pollen-bold (bold contents info)
(format "◊bold{%s}" contents))
(defun org-export-pollen-footnote-reference (footnote-reference _contents info)
"Transcode a FOOTNOTE-REFERENCE element from Org to Pollen.
CONTENTS is nil. INFO is a plist holding contextual information."
;; (format "◊footnote-reference[%s]" (org-export-get-footnote-number footnote-reference info))
(format "◊footnote-reference[\"%s\"]{%s}"
(number-to-string (org-export-get-footnote-number footnote-reference info))
(org-trim (org-export-data (org-export-get-footnote-definition footnote-reference info) info))))
(defun org-export-pollen-inline-src-block (inline-src-block _contents info)
"Transcode an INLINE-SRC-BLOCK element from Org to Pollen.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
(format "◊inline-src-block[%s]{%s}"
(org-element-property :language inline-src-block)
(org-element-property :value inline-src-block)))
(defun org-export-pollen-italic (bold contents info)
(format "◊italic{%s}" contents))
(defun org-export-pollen-keyword(keyword _contents _info)
(format "◊define-meta[org-%s]{%s}"
(org-element-property :key keyword)
(org-element-property :value keyword)))
(defun org-export-pollen-link (link desc _info)
"Transcode a LINK object from Org to Pollen.
DESC is the description part of the link, or the empty string.
INFO is a plist holding contextual information."
;; TODO: Not finished
(format "◊keyword[%s]{%s}"
(org-element-property :raw-link keyword)
desc))
(defun org-org-export-node-property (node-property _contents _info)
"Transcode a NODE-PROPERTY element from Org to Pollen.
CONTENTS is nil. INFO is a plist holding contextual
information."
(format "%s:%s"
(org-element-property :key node-property)
(let ((value (org-element-property :value node-property)))
(if value (concat " " value) ""))))
(defun org-export-pollen-property-drawer (property-drawer contents _info)
(and (org-string-nw-p contents)
(format "◊property-drawer{%s}" contents)))
(defun org-export-pollen-code (code contents info)
(format "◊code[%s]{%s}" (org-element-property :language code) (org-element-property :value code)))
(defun org-export-pollen-headline (headline contents info)
(let ((level (org-export-get-relative-level headline info)))
(unless (org-element-property :footnote-section-p headline)
(format "◊h%s{%s}\n%s"
level
(plist-get (cl-second headline) :raw-value)
contents))))
(defun org-export-pollen-statistics-cookie (statistics-cookie _contents _info)
"Transcode a STATISTICS-COOKIE object from Org to Pollen.
CONTENTS is nil. INFO is a plist holding contextual information."
(org-element-property :value statistics-cookie))
(defun org-export-pollen-target (target _contents info)
"Transcode a TARGET object from Org to Pollen.
CONTENTS is nil. INFO is a plist holding contextual
information."
(format "◊{%s}" (org-export-get-reference target info)))