git.iko.soy/typeable/pandoc
on master help sign in
Org writer: add :PROPERTIES: drawer support
cd3282bAlbert Krewinkel
src/Text/Pandoc/Writers/Org.hs+21−2
@@ -137,10 +137,13 @@ blockToOrg (RawBlock f str) | isRawFormat f =
137 return $ text str
137 return $ text str
138blockToOrg (RawBlock _ _) = return empty
138blockToOrg (RawBlock _ _) = return empty
139blockToOrg HorizontalRule = return $ blankline $$ "--------------" $$ blankline
139blockToOrg HorizontalRule = return $ blankline $$ "--------------" $$ blankline
140−blockToOrg (Header level _ inlines) = do
140+blockToOrg (Header level attr inlines) = do
141 contents <- inlineListToOrg inlines
141 contents <- inlineListToOrg inlines
142 let headerStr = text $ if level > 999 then " " else replicate level '*'
142 let headerStr = text $ if level > 999 then " " else replicate level '*'
143+ let drawerStr = if attr == nullAttr
144+ then empty
145+ else cr <> nest (level + 1) (propertiesDrawer attr)
143− return $ headerStr <> " " <> contents <> blankline
146+ return $ headerStr <> " " <> contents <> drawerStr <> blankline
144blockToOrg (CodeBlock (_,classes,_) str) = do
147blockToOrg (CodeBlock (_,classes,_) str) = do
145 opts <- stOptions <$> get
148 opts <- stOptions <$> get
146 let tabstop = writerTabStop opts
149 let tabstop = writerTabStop opts
@@ -230,6 +233,22 @@ definitionListItemToOrg (label, defs) = do
230 contents <- liftM vcat $ mapM blockListToOrg defs
233 contents <- liftM vcat $ mapM blockListToOrg defs
231 return $ hang 3 "- " $ label' <> " :: " <> (contents <> cr)
234 return $ hang 3 "- " $ label' <> " :: " <> (contents <> cr)
232
235
236+-- | Convert list of key/value pairs to Org :PROPERTIES: drawer.
237+propertiesDrawer :: Attr -> Doc
238+propertiesDrawer (ident, classes, kv) =
239+ let
240+ drawerStart = text ":PROPERTIES:"
241+ drawerEnd = text ":END:"
242+ kv' = if (classes == mempty) then kv else ("class", unwords classes):kv
243+ kv'' = if (ident == mempty) then kv' else ("id", ident):kv'
244+ properties = vcat $ map kvToOrgProperty kv''
245+ in
246+ drawerStart <> cr <> properties <> cr <> drawerEnd
247+ where
248+ kvToOrgProperty :: (String, String) -> Doc
249+ kvToOrgProperty (key, value) =
250+ text ":" <> text key <> text ": " <> text value <> cr
251+
233-- | Convert list of Pandoc block elements to Org.
252-- | Convert list of Pandoc block elements to Org.
234blockListToOrg :: [Block] -- ^ List of block elements
253blockListToOrg :: [Block] -- ^ List of block elements
235 -> State WriterState Doc
254 -> State WriterState Doc
tests/writer.org+93
@@ -9,30 +9,60 @@ markdown test suite.
9--------------
9--------------
10
10
11* Headers
11* Headers
12+ :PROPERTIES:
13+ :id: headers
14+ :END:
12
15
13** Level 2 with an [[/url][embedded link]]
16** Level 2 with an [[/url][embedded link]]
17+ :PROPERTIES:
18+ :id: level-2-with-an-embedded-link
19+ :END:
14
20
15*** Level 3 with /emphasis/
21*** Level 3 with /emphasis/
22+ :PROPERTIES:
23+ :id: level-3-with-emphasis
24+ :END:
16
25
17**** Level 4
26**** Level 4
27+ :PROPERTIES:
28+ :id: level-4
29+ :END:
18
30
19***** Level 5
31***** Level 5
32+ :PROPERTIES:
33+ :id: level-5
34+ :END:
20
35
21* Level 1
36* Level 1
37+ :PROPERTIES:
38+ :id: level-1
39+ :END:
22
40
23** Level 2 with /emphasis/
41** Level 2 with /emphasis/
42+ :PROPERTIES:
43+ :id: level-2-with-emphasis
44+ :END:
24
45
25*** Level 3
46*** Level 3
47+ :PROPERTIES:
48+ :id: level-3
49+ :END:
26
50
27with no blank line
51with no blank line
28
52
29** Level 2
53** Level 2
54+ :PROPERTIES:
55+ :id: level-2
56+ :END:
30
57
31with no blank line
58with no blank line
32
59
33--------------
60--------------
34
61
35* Paragraphs
62* Paragraphs
63+ :PROPERTIES:
64+ :id: paragraphs
65+ :END:
36
66
37Here's a regular paragraph.
67Here's a regular paragraph.
38
68
@@ -48,6 +78,9 @@ here.
48--------------
78--------------
49
79
50* Block Quotes
80* Block Quotes
81+ :PROPERTIES:
82+ :id: block-quotes
83+ :END:
51
84
52E-mail style:
85E-mail style:
53
86
@@ -87,6 +120,9 @@ And a following paragraph.
87--------------
120--------------
88
121
89* Code Blocks
122* Code Blocks
123+ :PROPERTIES:
124+ :id: code-blocks
125+ :END:
90
126
91Code:
127Code:
92
128
@@ -111,8 +147,14 @@ And:
111--------------
147--------------
112
148
113* Lists
149* Lists
150+ :PROPERTIES:
151+ :id: lists
152+ :END:
114
153
115** Unordered
154** Unordered
155+ :PROPERTIES:
156+ :id: unordered
157+ :END:
116
158
117Asterisks tight:
159Asterisks tight:
118
160
@@ -157,6 +199,9 @@ Minuses loose:
157- Minus 3
199- Minus 3
158
200
159** Ordered
201** Ordered
202+ :PROPERTIES:
203+ :id: ordered
204+ :END:
160
205
161Tight:
206Tight:
162
207
@@ -197,6 +242,9 @@ Multiple paragraphs:
1973. Item 3.
2423. Item 3.
198
243
199** Nested
244** Nested
245+ :PROPERTIES:
246+ :id: nested
247+ :END:
200
248
201- Tab
249- Tab
202
250
@@ -228,6 +276,9 @@ Same thing but with paragraphs:
2283. Third
2763. Third
229
277
230** Tabs and spaces
278** Tabs and spaces
279+ :PROPERTIES:
280+ :id: tabs-and-spaces
281+ :END:
231
282
232- this is a list item indented with tabs
283- this is a list item indented with tabs
233
284
@@ -238,6 +289,9 @@ Same thing but with paragraphs:
238 - this is an example list item indented with spaces
289 - this is an example list item indented with spaces
239
290
240** Fancy list markers
291** Fancy list markers
292+ :PROPERTIES:
293+ :id: fancy-list-markers
294+ :END:
241
295
2422) begins with 2
2962) begins with 2
2433) and now 3
2973) and now 3
@@ -276,6 +330,9 @@ B. Williams
276--------------
330--------------
277
331
278* Definition Lists
332* Definition Lists
333+ :PROPERTIES:
334+ :id: definition-lists
335+ :END:
279
336
280Tight using spaces:
337Tight using spaces:
281
338
@@ -342,6 +399,9 @@ Blank line after term, indented marker, alternate markers:
342 2. sublist
399 2. sublist
343
400
344* HTML Blocks
401* HTML Blocks
402+ :PROPERTIES:
403+ :id: html-blocks
404+ :END:
345
405
346Simple block on one line:
406Simple block on one line:
347
407
@@ -569,6 +629,9 @@ Hr's:
569--------------
629--------------
570
630
571* Inline Markup
631* Inline Markup
632+ :PROPERTIES:
633+ :id: inline-markup
634+ :END:
572
635
573This is /emphasized/, and so /is this/.
636This is /emphasized/, and so /is this/.
574
637
@@ -598,6 +661,9 @@ spaces: a\^b c\^d, a~b c~d.
598--------------
661--------------
599
662
600* Smart quotes, ellipses, dashes
663* Smart quotes, ellipses, dashes
664+ :PROPERTIES:
665+ :id: smart-quotes-ellipses-dashes
666+ :END:
601
667
602"Hello," said the spider. "'Shelob' is my name."
668"Hello," said the spider. "'Shelob' is my name."
603
669
@@ -619,6 +685,9 @@ Ellipses...and...and....
619--------------
685--------------
620
686
621* LaTeX
687* LaTeX
688+ :PROPERTIES:
689+ :id: latex
690+ :END:
622
691
623- \cite[22-23]{smith.1899}
692- \cite[22-23]{smith.1899}
624- $2+2=4$
693- $2+2=4$
@@ -649,6 +718,9 @@ Cat & 1 \\ \hline
649--------------
718--------------
650
719
651* Special Characters
720* Special Characters
721+ :PROPERTIES:
722+ :id: special-characters
723+ :END:
652
724
653Here is some unicode:
725Here is some unicode:
654
726
@@ -703,8 +775,14 @@ Minus: -
703--------------
775--------------
704
776
705* Links
777* Links
778+ :PROPERTIES:
779+ :id: links
780+ :END:
706
781
707** Explicit
782** Explicit
783+ :PROPERTIES:
784+ :id: explicit
785+ :END:
708
786
709Just a [[/url/][URL]].
787Just a [[/url/][URL]].
710
788
@@ -725,6 +803,9 @@ Just a [[/url/][URL]].
725[[][Empty]].
803[[][Empty]].
726
804
727** Reference
805** Reference
806+ :PROPERTIES:
807+ :id: reference
808+ :END:
728
809
729Foo [[/url/][bar]].
810Foo [[/url/][bar]].
730
811
@@ -753,6 +834,9 @@ Foo [[/url/][bar]].
753Foo [[/url/][biz]].
834Foo [[/url/][biz]].
754
835
755** With ampersands
836** With ampersands
837+ :PROPERTIES:
838+ :id: with-ampersands
839+ :END:
756
840
757Here's a [[http://example.com/?foo=1&bar=2][link with an ampersand in the
841Here's a [[http://example.com/?foo=1&bar=2][link with an ampersand in the
758URL]].
842URL]].
@@ -764,6 +848,9 @@ Here's an [[/script?foo=1&bar=2][inline link]].
764Here's an [[/script?foo=1&bar=2][inline link in pointy braces]].
848Here's an [[/script?foo=1&bar=2][inline link in pointy braces]].
765
849
766** Autolinks
850** Autolinks
851+ :PROPERTIES:
852+ :id: autolinks
853+ :END:
767
854
768With an ampersand: [[http://example.com/?foo=1&bar=2]]
855With an ampersand: [[http://example.com/?foo=1&bar=2]]
769
856
@@ -786,6 +873,9 @@ Auto-links should not occur here: =<http://example.com/>=
786--------------
873--------------
787
874
788* Images
875* Images
876+ :PROPERTIES:
877+ :id: images
878+ :END:
789
879
790From "Voyage dans la Lune" by Georges Melies (1902):
880From "Voyage dans la Lune" by Georges Melies (1902):
791
881
@@ -797,6 +887,9 @@ Here is a movie [[movie.jpg]] icon.
797--------------
887--------------
798
888
799* Footnotes
889* Footnotes
890+ :PROPERTIES:
891+ :id: footnotes
892+ :END:
800
893
801Here is a footnote reference, [1] and another. [2] This should /not/ be a
894Here is a footnote reference, [1] and another. [2] This should /not/ be a
802footnote reference, because it contains a space.[\^my note] Here is an inline
895footnote reference, because it contains a space.[\^my note] Here is an inline