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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
|
{-# LANGUAGE OverloadedStrings #-}
module Tests.Readers.Org (tests) where
import Text.Pandoc.Definition
import Test.Framework
import Tests.Helpers
import Text.Pandoc.Builder
import Text.Pandoc
import Data.List (intersperse)
import Text.Pandoc.Error
org :: String -> Pandoc
org = handleError . readOrg def
orgSmart :: String -> Pandoc
orgSmart = handleError . readOrg def { readerSmart = True }
infix 4 =:
(=:) :: ToString c
=> String -> (String, c) -> Test
(=:) = test org
spcSep :: [Inlines] -> Inlines
spcSep = mconcat . intersperse space
simpleTable' :: Int
-> [Blocks]
-> [[Blocks]]
-> Blocks
simpleTable' n = table "" (take n $ repeat (AlignDefault, 0.0))
tests :: [Test]
tests =
[ testGroup "Inlines" $
[ "Plain String" =:
"Hello, World" =?>
para (spcSep [ "Hello,", "World" ])
, "Emphasis" =:
"/Planet Punk/" =?>
para (emph . spcSep $ ["Planet", "Punk"])
, "Strong" =:
"*Cider*" =?>
para (strong "Cider")
, "Strong Emphasis" =:
"/*strength*/" =?>
para (emph . strong $ "strength")
, "Strikeout" =:
"+Kill Bill+" =?>
para (strikeout . spcSep $ [ "Kill", "Bill" ])
, "Verbatim" =:
"=Robot.rock()=" =?>
para (code "Robot.rock()")
, "Code" =:
"~word for word~" =?>
para (code "word for word")
, "Math $..$" =:
"$E=mc^2$" =?>
para (math "E=mc^2")
, "Math $$..$$" =:
"$$E=mc^2$$" =?>
para (displayMath "E=mc^2")
, "Math \\[..\\]" =:
"\\[E=ℎν\\]" =?>
para (displayMath "E=ℎν")
, "Math \\(..\\)" =:
"\\(σ_x σ_p ≥ \\frac{ℏ}{2}\\)" =?>
para (math "σ_x σ_p ≥ \\frac{ℏ}{2}")
, "Symbol" =:
"A * symbol" =?>
para (str "A" <> space <> str "*" <> space <> "symbol")
, "Superscript simple expression" =:
"2^-λ" =?>
para (str "2" <> superscript "-λ")
, "Superscript multi char" =:
"2^{n-1}" =?>
para (str "2" <> superscript "n-1")
, "Subscript simple expression" =:
"a_n" =?>
para (str "a" <> subscript "n")
, "Subscript multi char" =:
"a_{n+1}" =?>
para (str "a" <> subscript "n+1")
, "Linebreak" =:
"line \\\\ \nbreak" =?>
para ("line" <> linebreak <> "break")
, "Inline note" =:
"[fn::Schreib mir eine E-Mail]" =?>
para (note $ para "Schreib mir eine E-Mail")
, "Markup-chars not occuring on word break are symbols" =:
unlines [ "this+that+ +so+on"
, "seven*eight* nine*"
, "+not+funny+"
] =?>
para ("this+that+ +so+on" <> softbreak <>
"seven*eight* nine*" <> softbreak <>
strikeout "not+funny")
, "No empty markup" =:
"// ** __ ++ == ~~ $$" =?>
para (spcSep [ "//", "**", "__", "++", "==", "~~", "$$" ])
, "Adherence to Org's rules for markup borders" =:
"/t/& a/ / ./r/ (*l*) /e/! /b/." =?>
para (spcSep [ emph $ "t/&" <> space <> "a"
, "/"
, "./r/"
, "(" <> (strong "l") <> ")"
, (emph "e") <> "!"
, (emph "b") <> "."
])
, "Quotes are forbidden border chars" =:
"/'nope/ *nope\"*" =?>
para ("/'nope/" <> space <> "*nope\"*")
, "Commata are forbidden border chars" =:
"/nada,/" =?>
para "/nada,/"
, "Markup should work properly after a blank line" =:
unlines ["foo", "", "/bar/"] =?>
(para $ text "foo") <> (para $ emph $ text "bar")
, "Inline math must stay within three lines" =:
unlines [ "$a", "b", "c$", "$d", "e", "f", "g$" ] =?>
para ((math "a\nb\nc") <> softbreak <>
"$d" <> softbreak <> "e" <> softbreak <>
"f" <> softbreak <> "g$")
, "Single-character math" =:
"$a$ $b$! $c$?" =?>
para (spcSep [ math "a"
, "$b$!"
, (math "c") <> "?"
])
, "Markup may not span more than two lines" =:
"/this *is +totally\nnice+ not*\nemph/" =?>
para ("/this" <> space <>
strong ("is" <> space <>
strikeout ("totally" <>
softbreak <> "nice") <>
space <> "not") <>
softbreak <> "emph/")
, "Sub- and superscript expressions" =:
unlines [ "a_(a(b)(c)d)"
, "e^(f(g)h)"
, "i_(jk)l)"
, "m^()n"
, "o_{p{q{}r}}"
, "s^{t{u}v}"
, "w_{xy}z}"
, "1^{}2"
, "3_{{}}"
, "4^(a(*b(c*)d))"
] =?>
para (mconcat $ intersperse softbreak
[ "a" <> subscript "(a(b)(c)d)"
, "e" <> superscript "(f(g)h)"
, "i" <> (subscript "(jk)") <> "l)"
, "m" <> (superscript "()") <> "n"
, "o" <> subscript "p{q{}r}"
, "s" <> superscript "t{u}v"
, "w" <> (subscript "xy") <> "z}"
, "1" <> (superscript "") <> "2"
, "3" <> subscript "{}"
, "4" <> superscript ("(a(" <> strong "b(c" <> ")d))")
])
, "Verbatim text can contain equal signes (=)" =:
"=is_subst = True=" =?>
para (code "is_subst = True")
, "Image" =:
"[[./sunset.jpg]]" =?>
(para $ image "./sunset.jpg" "" "")
, "Image with explicit file: prefix" =:
"[[file:sunrise.jpg]]" =?>
(para $ image "sunrise.jpg" "" "")
, "Explicit link" =:
"[[http://zeitlens.com/][pseudo-random /nonsense/]]" =?>
(para $ link "http://zeitlens.com/" ""
("pseudo-random" <> space <> emph "nonsense"))
, "Self-link" =:
"[[http://zeitlens.com/]]" =?>
(para $ link "http://zeitlens.com/" "" "http://zeitlens.com/")
, "Absolute file link" =:
"[[/url][hi]]" =?>
(para $ link "file:///url" "" "hi")
, "Link to file in parent directory" =:
"[[../file.txt][moin]]" =?>
(para $ link "../file.txt" "" "moin")
, "Empty link (for gitit interop)" =:
"[[][New Link]]" =?>
(para $ link "" "" "New Link")
, "Image link" =:
"[[sunset.png][file:dusk.svg]]" =?>
(para $ link "sunset.png" "" (image "dusk.svg" "" ""))
, "Image link with non-image target" =:
"[[http://example.com][./logo.png]]" =?>
(para $ link "http://example.com" "" (image "./logo.png" "" ""))
, "Plain link" =:
"Posts on http://zeitlens.com/ can be funny at times." =?>
(para $ spcSep [ "Posts", "on"
, link "http://zeitlens.com/" "" "http://zeitlens.com/"
, "can", "be", "funny", "at", "times."
])
, "Angle link" =:
"Look at <http://moltkeplatz.de> for fnords." =?>
(para $ spcSep [ "Look", "at"
, link "http://moltkeplatz.de" "" "http://moltkeplatz.de"
, "for", "fnords."
])
, "Absolute file link" =:
"[[file:///etc/passwd][passwd]]" =?>
(para $ link "file:///etc/passwd" "" "passwd")
, "File link" =:
"[[file:target][title]]" =?>
(para $ link "target" "" "title")
, "Anchor" =:
"<<anchor>> Link here later." =?>
(para $ spanWith ("anchor", [], []) mempty <>
"Link" <> space <> "here" <> space <> "later.")
, "Inline code block" =:
"src_emacs-lisp{(message \"Hello\")}" =?>
(para $ codeWith ( ""
, [ "commonlisp", "rundoc-block" ]
, [ ("rundoc-language", "emacs-lisp") ])
"(message \"Hello\")")
, "Inline code block with arguments" =:
"src_sh[:export both :results output]{echo 'Hello, World'}" =?>
(para $ codeWith ( ""
, [ "bash", "rundoc-block" ]
, [ ("rundoc-language", "sh")
, ("rundoc-export", "both")
, ("rundoc-results", "output")
]
)
"echo 'Hello, World'")
, "Inline code block with toggle" =:
"src_sh[:toggle]{echo $HOME}" =?>
(para $ codeWith ( ""
, [ "bash", "rundoc-block" ]
, [ ("rundoc-language", "sh")
, ("rundoc-toggle", "yes")
]
)
"echo $HOME")
, "Citation" =:
"[@nonexistent]" =?>
let citation = Citation
{ citationId = "nonexistent"
, citationPrefix = []
, citationSuffix = []
, citationMode = NormalCitation
, citationNoteNum = 0
, citationHash = 0}
in (para $ cite [citation] "[@nonexistent]")
, "Citation containing text" =:
"[see @item1 p. 34-35]" =?>
let citation = Citation
{ citationId = "item1"
, citationPrefix = [Str "see"]
, citationSuffix = [Space ,Str "p.",Space,Str "34-35"]
, citationMode = NormalCitation
, citationNoteNum = 0
, citationHash = 0}
in (para $ cite [citation] "[see @item1 p. 34-35]")
, "Org-ref simple citation" =:
"cite:pandoc" =?>
let citation = Citation
{ citationId = "pandoc"
, citationPrefix = mempty
, citationSuffix = mempty
, citationMode = AuthorInText
, citationNoteNum = 0
, citationHash = 0
}
in (para $ cite [citation] "cite:pandoc")
, "Org-ref simple citep citation" =:
"citep:pandoc" =?>
let citation = Citation
{ citationId = "pandoc"
, citationPrefix = mempty
, citationSuffix = mempty
, citationMode = NormalCitation
, citationNoteNum = 0
, citationHash = 0
}
in (para $ cite [citation] "citep:pandoc")
, "Org-ref extended citation" =:
"[[citep:Dominik201408][See page 20::, for example]]" =?>
let citation = Citation
{ citationId = "Dominik201408"
, citationPrefix = toList "See page 20"
, citationSuffix = toList ", for example"
, citationMode = NormalCitation
, citationNoteNum = 0
, citationHash = 0
}
in (para $ cite [citation] "[[citep:Dominik201408][See page 20::, for example]]")
, testGroup "Berkeley-style citations" $
let pandocCite = Citation
{ citationId = "Pandoc"
, citationPrefix = mempty
, citationSuffix = mempty
, citationMode = NormalCitation
, citationNoteNum = 0
, citationHash = 0
}
pandocInText = pandocCite { citationMode = AuthorInText }
dominikCite = Citation
{ citationId = "Dominik201408"
, citationPrefix = mempty
, citationSuffix = mempty
, citationMode = NormalCitation
, citationNoteNum = 0
, citationHash = 0
}
dominikInText = dominikCite { citationMode = AuthorInText }
in [
"Berkeley-style in-text citation" =:
"See @Dominik201408." =?>
(para $ "See "
<> cite [dominikInText] "@Dominik201408"
<> ".")
, "Berkeley-style parenthetical citation list" =:
"[(cite): see; @Dominik201408;also @Pandoc; and others]" =?>
let pandocCite' = pandocCite {
citationPrefix = toList "also"
, citationSuffix = toList "and others"
}
dominikCite' = dominikCite {
citationPrefix = toList "see"
}
in (para $ cite [dominikCite', pandocCite'] "")
, "Berkeley-style plain citation list" =:
"[cite: See; @Dominik201408; and @Pandoc; and others]" =?>
let pandocCite' = pandocInText {
citationPrefix = toList "and"
}
in (para $ "See "
<> cite [dominikInText] ""
<> "," <> space
<> cite [pandocCite'] ""
<> "," <> space <> "and others")
]
, "Inline LaTeX symbol" =:
"\\dots" =?>
para "…"
, "Inline LaTeX command" =:
"\\textit{Emphasised}" =?>
para (emph "Emphasised")
, "Inline LaTeX command with spaces" =:
"\\emph{Emphasis mine}" =?>
para (emph "Emphasis mine")
, "Inline LaTeX math symbol" =:
"\\tau" =?>
para (emph "τ")
, "Unknown inline LaTeX command" =:
"\\notacommand{foo}" =?>
para (rawInline "latex" "\\notacommand{foo}")
, "Export snippet" =:
"@@html:<kbd>M-x org-agenda</kbd>@@" =?>
para (rawInline "html" "<kbd>M-x org-agenda</kbd>")
, "MathML symbol in LaTeX-style" =:
"There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: '\\nbsp')." =?>
para ("There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: ' ').")
, "MathML symbol in LaTeX-style, including braces" =:
"\\Aacute{}stor" =?>
para "Ástor"
, "MathML copy sign" =:
"\\copy" =?>
para "©"
, "MathML symbols, space separated" =:
"\\ForAll \\Auml" =?>
para "∀ Ä"
, "LaTeX citation" =:
"\\cite{Coffee}" =?>
let citation = Citation
{ citationId = "Coffee"
, citationPrefix = []
, citationSuffix = []
, citationMode = NormalCitation
, citationNoteNum = 0
, citationHash = 0}
in (para . cite [citation] $ rawInline "latex" "\\cite{Coffee}")
]
, testGroup "Meta Information" $
[ "Comment" =:
"# Nothing to see here" =?>
(mempty::Blocks)
, "Not a comment" =:
"#-tag" =?>
para "#-tag"
, "Comment surrounded by Text" =:
unlines [ "Before"
, "# Comment"
, "After"
] =?>
mconcat [ para "Before"
, para "After"
]
, "Title" =:
"#+TITLE: Hello, World" =?>
let titleInline = toList $ "Hello," <> space <> "World"
meta = setMeta "title" (MetaInlines titleInline) $ nullMeta
in Pandoc meta mempty
, "Author" =:
"#+author: Albert /Emacs-Fanboy/ Krewinkel" =?>
let author = toList . spcSep $ [ "Albert", emph "Emacs-Fanboy", "Krewinkel" ]
meta = setMeta "author" (MetaList [MetaInlines author]) $ nullMeta
in Pandoc meta mempty
, "Multiple authors" =:
"#+author: James Dewey Watson, Francis Harry Compton Crick " =?>
let watson = MetaInlines $ toList "James Dewey Watson"
crick = MetaInlines $ toList "Francis Harry Compton Crick"
meta = setMeta "author" (MetaList [watson, crick]) $ nullMeta
in Pandoc meta mempty
, "Date" =:
"#+Date: Feb. *28*, 2014" =?>
let date = toList . spcSep $ [ "Feb.", (strong "28") <> ",", "2014" ]
meta = setMeta "date" (MetaInlines date) $ nullMeta
in Pandoc meta mempty
, "Description" =:
"#+DESCRIPTION: Explanatory text" =?>
let description = "Explanatory text"
meta = setMeta "description" (MetaString description) $ nullMeta
in Pandoc meta mempty
, "Properties drawer" =:
unlines [ " :PROPERTIES:"
, " :setting: foo"
, " :END:"
] =?>
(mempty::Blocks)
, "LaTeX_headers options are translated to header-includes" =:
"#+LaTeX_header: \\usepackage{tikz}" =?>
let latexInlines = rawInline "latex" "\\usepackage{tikz}"
inclList = MetaList [MetaInlines (toList latexInlines)]
meta = setMeta "header-includes" inclList nullMeta
in Pandoc meta mempty
, "LaTeX_class option is translated to documentclass" =:
"#+LATEX_CLASS: article" =?>
let meta = setMeta "documentclass" (MetaString "article") nullMeta
in Pandoc meta mempty
, "LaTeX_class_options is translated to classoption" =:
"#+LATEX_CLASS_OPTIONS: [a4paper]" =?>
let meta = setMeta "classoption" (MetaString "a4paper") nullMeta
in Pandoc meta mempty
, "LaTeX_class_options is translated to classoption" =:
"#+html_head: <meta/>" =?>
let html = rawInline "html" "<meta/>"
inclList = MetaList [MetaInlines (toList html)]
meta = setMeta "header-includes" inclList nullMeta
in Pandoc meta mempty
, "later meta definitions take precedence" =:
unlines [ "#+AUTHOR: this will not be used"
, "#+author: Max"
] =?>
let author = MetaInlines [Str "Max"]
meta = setMeta "author" (MetaList [author]) $ nullMeta
in Pandoc meta mempty
, "Logbook drawer" =:
unlines [ " :LogBook:"
, " - State \"DONE\" from \"TODO\" [2014-03-03 Mon 11:00]"
, " :END:"
] =?>
(mempty::Blocks)
, "Drawer surrounded by text" =:
unlines [ "Before"
, ":PROPERTIES:"
, ":END:"
, "After"
] =?>
para "Before" <> para "After"
, "Drawer markers must be the only text in the line" =:
unlines [ " :LOGBOOK: foo"
, " :END: bar"
] =?>
para (":LOGBOOK: foo" <> softbreak <> ":END: bar")
, "Drawers can be arbitrary" =:
unlines [ ":FOO:"
, "/bar/"
, ":END:"
] =?>
divWith (mempty, ["FOO", "drawer"], mempty) (para $ emph "bar")
, "Anchor reference" =:
unlines [ "<<link-here>> Target."
, ""
, "[[link-here][See here!]]"
] =?>
(para (spanWith ("link-here", [], []) mempty <> "Target.") <>
para (link "#link-here" "" ("See" <> space <> "here!")))
, "Search links are read as emph" =:
"[[Wally][Where's Wally?]]" =?>
(para (emph $ "Where's" <> space <> "Wally?"))
, "Link to nonexistent anchor" =:
unlines [ "<<link-here>> Target."
, ""
, "[[link$here][See here!]]"
] =?>
(para (spanWith ("link-here", [], []) mempty <> "Target.") <>
para (emph ("See" <> space <> "here!")))
, "Link abbreviation" =:
unlines [ "#+LINK: wp https://en.wikipedia.org/wiki/%s"
, "[[wp:Org_mode][Wikipedia on Org-mode]]"
] =?>
(para (link "https://en.wikipedia.org/wiki/Org_mode" ""
("Wikipedia" <> space <> "on" <> space <> "Org-mode")))
, "Link abbreviation, defined after first use" =:
unlines [ "[[zl:non-sense][Non-sense articles]]"
, "#+LINK: zl http://zeitlens.com/tags/%s.html"
] =?>
(para (link "http://zeitlens.com/tags/non-sense.html" ""
("Non-sense" <> space <> "articles")))
, "Link abbreviation, URL encoded arguments" =:
unlines [ "#+link: expl http://example.com/%h/foo"
, "[[expl:Hello, World!][Moin!]]"
] =?>
(para (link "http://example.com/Hello%2C%20World%21/foo" "" "Moin!"))
, "Link abbreviation, append arguments" =:
unlines [ "#+link: expl http://example.com/"
, "[[expl:foo][bar]]"
] =?>
(para (link "http://example.com/foo" "" "bar"))
, testGroup "export options"
[ "disable simple sub/superscript syntax" =:
unlines [ "#+OPTIONS: ^:nil"
, "a^b"
] =?>
para "a^b"
, "directly select drawers to be exported" =:
unlines [ "#+OPTIONS: d:(\"IMPORTANT\")"
, ":IMPORTANT:"
, "23"
, ":END:"
, ":BORING:"
, "very boring"
, ":END:"
] =?>
divWith (mempty, ["IMPORTANT", "drawer"], mempty) (para "23")
, "exclude drawers from being exported" =:
unlines [ "#+OPTIONS: d:(not \"BORING\")"
, ":IMPORTANT:"
, "5"
, ":END:"
, ":BORING:"
, "very boring"
, ":END:"
] =?>
divWith (mempty, ["IMPORTANT", "drawer"], mempty) (para "5")
, "don't include archive trees" =:
unlines [ "#+OPTIONS: arch:nil"
, "* old :ARCHIVE:"
] =?>
(mempty ::Blocks)
, "include complete archive trees" =:
unlines [ "#+OPTIONS: arch:t"
, "* old :ARCHIVE:"
, " boring"
] =?>
let tagSpan t = spanWith ("", ["tag"], [("data-tag-name", t)]) mempty
in mconcat [ headerWith ("old", [], mempty) 1 ("old" <> tagSpan "ARCHIVE")
, para "boring"
]
, "include archive tree header only" =:
unlines [ "#+OPTIONS: arch:headline"
, "* old :ARCHIVE:"
, " boring"
] =?>
let tagSpan t = spanWith ("", ["tag"], [("data-tag-name", t)]) mempty
in headerWith ("old", [], mempty) 1 ("old" <> tagSpan "ARCHIVE")
, "limit headline depth" =:
unlines [ "#+OPTIONS: H:2"
, "* section"
, "** subsection"
, "*** list item 1"
, "*** list item 2"
] =?>
mconcat [ headerWith ("section", [], []) 1 "section"
, headerWith ("subsection", [], []) 2 "subsection"
, orderedList [ para "list item 1", para "list item 2" ]
]
, "disable author export" =:
unlines [ "#+OPTIONS: author:nil"
, "#+AUTHOR: ShyGuy"
] =?>
Pandoc nullMeta mempty
, "disable creator export" =:
unlines [ "#+OPTIONS: creator:nil"
, "#+creator: The Architect"
] =?>
Pandoc nullMeta mempty
, "disable email export" =:
unlines [ "#+OPTIONS: email:nil"
, "#+email: no-mail-please@example.com"
] =?>
Pandoc nullMeta mempty
]
]
, testGroup "Basic Blocks" $
[ "Paragraph" =:
"Paragraph\n" =?>
para "Paragraph"
, "First Level Header" =:
"* Headline\n" =?>
headerWith ("headline", [], []) 1 "Headline"
, "Third Level Header" =:
"*** Third Level Headline\n" =?>
headerWith ("third-level-headline", [], [])
3
("Third" <> space <> "Level" <> space <> "Headline")
, "Compact Headers with Paragraph" =:
unlines [ "* First Level"
, "** Second Level"
, " Text"
] =?>
mconcat [ headerWith ("first-level", [], [])
1
("First" <> space <> "Level")
, headerWith ("second-level", [], [])
2
("Second" <> space <> "Level")
, para "Text"
]
, "Separated Headers with Paragraph" =:
unlines [ "* First Level"
, ""
, "** Second Level"
, ""
, " Text"
] =?>
mconcat [ headerWith ("first-level", [], [])
1
("First" <> space <> "Level")
, headerWith ("second-level", [], [])
2
("Second" <> space <> "Level")
, para "Text"
]
, "Headers not preceded by a blank line" =:
unlines [ "** eat dinner"
, "Spaghetti and meatballs tonight."
, "** walk dog"
] =?>
mconcat [ headerWith ("eat-dinner", [], [])
2
("eat" <> space <> "dinner")
, para $ spcSep [ "Spaghetti", "and", "meatballs", "tonight." ]
, headerWith ("walk-dog", [], [])
2
("walk" <> space <> "dog")
]
, "Tagged headers" =:
unlines [ "* Personal :PERSONAL:"
, "** Call Mom :@PHONE:"
, "** Call John :@PHONE:JOHN: "
] =?>
let tagSpan t = spanWith ("", ["tag"], [("data-tag-name", t)]) mempty
in mconcat [ headerWith ("personal", [], [])
1
("Personal" <> tagSpan "PERSONAL")
, headerWith ("call-mom", [], [])
2
("Call Mom" <> tagSpan "@PHONE")
, headerWith ("call-john", [], [])
2
("Call John" <> tagSpan "@PHONE" <> tagSpan "JOHN")
]
, "Untagged header containing colons" =:
"* This: is not: tagged" =?>
headerWith ("this-is-not-tagged", [], []) 1 "This: is not: tagged"
, "Header starting with strokeout text" =:
unlines [ "foo"
, ""
, "* +thing+ other thing"
] =?>
mconcat [ para "foo"
, headerWith ("thing-other-thing", [], [])
1
((strikeout "thing") <> " other thing")
]
, "Comment Trees" =:
unlines [ "* COMMENT A comment tree"
, " Not much going on here"
, "** This will be dropped"
, "* Comment tree above"
] =?>
headerWith ("comment-tree-above", [], []) 1 "Comment tree above"
, "Nothing but a COMMENT header" =:
"* COMMENT Test" =?>
(mempty::Blocks)
, "Tree with :noexport:" =:
unlines [ "* Should be ignored :archive:noexport:old:"
, "** Old stuff"
, " This is not going to be exported"
] =?>
(mempty::Blocks)
, "Subtree with :noexport:" =:
unlines [ "* Exported"
, "** This isn't exported :noexport:"
, "*** This neither"
, "** But this is"
] =?>
mconcat [ headerWith ("exported", [], []) 1 "Exported"
, headerWith ("but-this-is", [], []) 2 "But this is"
]
, "Preferences are treated as header attributes" =:
unlines [ "* foo"
, " :PROPERTIES:"
, " :custom_id: fubar"
, " :bar: baz"
, " :END:"
] =?>
headerWith ("fubar", [], [("bar", "baz")]) 1 "foo"
, "Headers marked with a unnumbered property get a class of the same name" =:
unlines [ "* Not numbered"
, " :PROPERTIES:"
, " :UNNUMBERED: t"
, " :END:"
] =?>
headerWith ("not-numbered", ["unnumbered"], []) 1 "Not numbered"
, "Paragraph starting with an asterisk" =:
"*five" =?>
para "*five"
, "Paragraph containing asterisk at beginning of line" =:
unlines [ "lucky"
, "*star"
] =?>
para ("lucky" <> softbreak <> "*star")
, "Example block" =:
unlines [ ": echo hello"
, ": echo dear tester"
] =?>
codeBlockWith ("", ["example"], []) "echo hello\necho dear tester\n"
, "Example block surrounded by text" =:
unlines [ "Greetings"
, ": echo hello"
, ": echo dear tester"
, "Bye"
] =?>
mconcat [ para "Greetings"
, codeBlockWith ("", ["example"], [])
"echo hello\necho dear tester\n"
, para "Bye"
]
, "Horizontal Rule" =:
unlines [ "before"
, "-----"
, "after"
] =?>
mconcat [ para "before"
, horizontalRule
, para "after"
]
, "Not a Horizontal Rule" =:
"----- five dashes" =?>
(para $ spcSep [ "-----", "five", "dashes" ])
, "Comment Block" =:
unlines [ "#+BEGIN_COMMENT"
, "stuff"
, "bla"
, "#+END_COMMENT"] =?>
(mempty::Blocks)
, testGroup "Figures" $
[ "Figure" =:
unlines [ "#+caption: A very courageous man."
, "#+name: goodguy"
, "[[file:edward.jpg]]"
] =?>
para (image "edward.jpg" "fig:goodguy" "A very courageous man.")
, "Figure with no name" =:
unlines [ "#+caption: I've been through the desert on this"
, "[[file:horse.png]]"
] =?>
para (image "horse.png" "fig:" "I've been through the desert on this")
, "Figure with `fig:` prefix in name" =:
unlines [ "#+caption: Used as a metapher in evolutionary biology."
, "#+name: fig:redqueen"
, "[[./the-red-queen.jpg]]"
] =?>
para (image "./the-red-queen.jpg" "fig:redqueen"
"Used as a metapher in evolutionary biology.")
, "Figure with HTML attributes" =:
unlines [ "#+CAPTION: mah brain just explodid"
, "#+NAME: lambdacat"
, "#+ATTR_HTML: :style color: blue :role button"
, "[[file:lambdacat.jpg]]"
] =?>
let kv = [("style", "color: blue"), ("role", "button")]
name = "fig:lambdacat"
caption = "mah brain just explodid"
in para (imageWith (mempty, mempty, kv) "lambdacat.jpg" name caption)
, "Labelled figure" =:
unlines [ "#+CAPTION: My figure"
, "#+LABEL: fig:myfig"
, "[[file:blub.png]]"
] =?>
let attr = ("fig:myfig", mempty, mempty)
in para (imageWith attr "blub.png" "fig:" "My figure")
]
, "Footnote" =:
unlines [ "A footnote[1]"
, ""
, "[1] First paragraph"
, ""
, "second paragraph"
] =?>
para (mconcat
[ "A", space, "footnote"
, note $ mconcat [ para ("First" <> space <> "paragraph")
, para ("second" <> space <> "paragraph")
]
])
, "Two footnotes" =:
unlines [ "Footnotes[fn:1][fn:2]"
, ""
, "[fn:1] First note."
, ""
, "[fn:2] Second note."
] =?>
para (mconcat
[ "Footnotes"
, note $ para ("First" <> space <> "note.")
, note $ para ("Second" <> space <> "note.")
])
, "Footnote followed by header" =:
unlines [ "Another note[fn:yay]"
, ""
, "[fn:yay] This is great!"
, ""
, "** Headline"
] =?>
mconcat
[ para (mconcat
[ "Another", space, "note"
, note $ para ("This" <> space <> "is" <> space <> "great!")
])
, headerWith ("headline", [], []) 2 "Headline"
]
]
, testGroup "Lists" $
[ "Simple Bullet Lists" =:
("- Item1\n" ++
"- Item2\n") =?>
bulletList [ plain "Item1"
, plain "Item2"
]
, "Indented Bullet Lists" =:
(" - Item1\n" ++
" - Item2\n") =?>
bulletList [ plain "Item1"
, plain "Item2"
]
, "Unindented *" =:
("- Item1\n" ++
"* Item2\n") =?>
bulletList [ plain "Item1"
] <>
headerWith ("item2", [], []) 1 "Item2"
, "Multi-line Bullet Lists" =:
("- *Fat\n" ++
" Tony*\n" ++
"- /Sideshow\n" ++
" Bob/") =?>
bulletList [ plain $ strong ("Fat" <> softbreak <> "Tony")
, plain $ emph ("Sideshow" <> softbreak <> "Bob")
]
, "Nested Bullet Lists" =:
("- Discovery\n" ++
" + One More Time\n" ++
" + Harder, Better, Faster, Stronger\n" ++
"- Homework\n" ++
" + Around the World\n"++
"- Human After All\n" ++
" + Technologic\n" ++
" + Robot Rock\n") =?>
bulletList [ mconcat
[ plain "Discovery"
, bulletList [ plain ("One" <> space <>
"More" <> space <>
"Time")
, plain ("Harder," <> space <>
"Better," <> space <>
"Faster," <> space <>
"Stronger")
]
]
, mconcat
[ plain "Homework"
, bulletList [ plain ("Around" <> space <>
"the" <> space <>
"World")
]
]
, mconcat
[ plain ("Human" <> space <> "After" <> space <> "All")
, bulletList [ plain "Technologic"
, plain ("Robot" <> space <> "Rock")
]
]
]
, "Bullet List with Decreasing Indent" =:
(" - Discovery\n\
\ - Human After All\n") =?>
mconcat [ bulletList [ plain "Discovery" ]
, bulletList [ plain ("Human" <> space <> "After" <> space <> "All")]
]
, "Header follows Bullet List" =:
(" - Discovery\n\
\ - Human After All\n\
\* Homework") =?>
mconcat [ bulletList [ plain "Discovery"
, plain ("Human" <> space <> "After" <> space <> "All")
]
, headerWith ("homework", [], []) 1 "Homework"
]
, "Bullet List Unindented with trailing Header" =:
("- Discovery\n\
\- Homework\n\
\* NotValidListItem") =?>
mconcat [ bulletList [ plain "Discovery"
, plain "Homework"
]
, headerWith ("notvalidlistitem", [], []) 1 "NotValidListItem"
]
, "Simple Ordered List" =:
("1. Item1\n" ++
"2. Item2\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Simple Ordered List with Parens" =:
("1) Item1\n" ++
"2) Item2\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Indented Ordered List" =:
(" 1. Item1\n" ++
" 2. Item2\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Nested Ordered Lists" =:
("1. One\n" ++
" 1. One-One\n" ++
" 2. One-Two\n" ++
"2. Two\n" ++
" 1. Two-One\n"++
" 2. Two-Two\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ mconcat
[ plain "One"
, orderedList [ plain "One-One"
, plain "One-Two"
]
]
, mconcat
[ plain "Two"
, orderedList [ plain "Two-One"
, plain "Two-Two"
]
]
]
in orderedListWith listStyle listStructure
, "Ordered List in Bullet List" =:
("- Emacs\n" ++
" 1. Org\n") =?>
bulletList [ (plain "Emacs") <>
(orderedList [ plain "Org"])
]
, "Bullet List in Ordered List" =:
("1. GNU\n" ++
" - Freedom\n") =?>
orderedList [ (plain "GNU") <> bulletList [ (plain "Freedom") ] ]
, "Definition List" =:
unlines [ "- PLL :: phase-locked loop"
, "- TTL ::"
, " transistor-transistor logic"
, "- PSK :: phase-shift keying"
, ""
, " a digital modulation scheme"
] =?>
definitionList [ ("PLL", [ plain $ "phase-locked" <> space <> "loop" ])
, ("TTL", [ plain $ "transistor-transistor" <> space <>
"logic" ])
, ("PSK", [ mconcat
[ para $ "phase-shift" <> space <> "keying"
, para $ spcSep [ "a", "digital"
, "modulation", "scheme" ]
]
])
]
, "Definition list with multi-word term" =:
" - Elijah Wood :: He plays Frodo" =?>
definitionList [ ("Elijah" <> space <> "Wood", [plain $ "He" <> space <> "plays" <> space <> "Frodo"])]
, "Compact definition list" =:
unlines [ "- ATP :: adenosine 5' triphosphate"
, "- DNA :: deoxyribonucleic acid"
, "- PCR :: polymerase chain reaction"
, ""
] =?>
definitionList
[ ("ATP", [ plain $ spcSep [ "adenosine", "5'", "triphosphate" ] ])
, ("DNA", [ plain $ spcSep [ "deoxyribonucleic", "acid" ] ])
, ("PCR", [ plain $ spcSep [ "polymerase", "chain", "reaction" ] ])
]
, "Definition List With Trailing Header" =:
"- definition :: list\n\
\- cool :: defs\n\
\* header" =?>
mconcat [ definitionList [ ("definition", [plain "list"])
, ("cool", [plain "defs"])
]
, headerWith ("header", [], []) 1 "header"
]
, "Definition lists double-colon markers must be surrounded by whitespace" =:
"- std::cout" =?>
bulletList [ plain "std::cout" ]
, "Loose bullet list" =:
unlines [ "- apple"
, ""
, "- orange"
, ""
, "- peach"
] =?>
bulletList [ para "apple"
, para "orange"
, para "peach"
]
, "Recognize preceding paragraphs in non-list contexts" =:
unlines [ "CLOSED: [2015-10-19 Mon 15:03]"
, "- Note taken on [2015-10-19 Mon 13:24]"
] =?>
mconcat [ para "CLOSED: [2015-10-19 Mon 15:03]"
, bulletList [ plain "Note taken on [2015-10-19 Mon 13:24]" ]
]
]
, testGroup "Tables"
[ "Single cell table" =:
"|Test|" =?>
simpleTable' 1 mempty [[plain "Test"]]
, "Multi cell table" =:
"| One | Two |" =?>
simpleTable' 2 mempty [ [ plain "One", plain "Two" ] ]
, "Multi line table" =:
unlines [ "| One |"
, "| Two |"
, "| Three |"
] =?>
simpleTable' 1 mempty
[ [ plain "One" ]
, [ plain "Two" ]
, [ plain "Three" ]
]
, "Empty table" =:
"||" =?>
simpleTable' 1 mempty [[mempty]]
, "Glider Table" =:
unlines [ "| 1 | 0 | 0 |"
, "| 0 | 1 | 1 |"
, "| 1 | 1 | 0 |"
] =?>
simpleTable' 3 mempty
[ [ plain "1", plain "0", plain "0" ]
, [ plain "0", plain "1", plain "1" ]
, [ plain "1", plain "1", plain "0" ]
]
, "Table between Paragraphs" =:
unlines [ "Before"
, "| One | Two |"
, "After"
] =?>
mconcat [ para "Before"
, simpleTable' 2 mempty [ [ plain "One", plain "Two" ] ]
, para "After"
]
, "Table with Header" =:
unlines [ "| Species | Status |"
, "|--------------+--------------|"
, "| cervisiae | domesticated |"
, "| paradoxus | wild |"
] =?>
simpleTable [ plain "Species", plain "Status" ]
[ [ plain "cervisiae", plain "domesticated" ]
, [ plain "paradoxus", plain "wild" ]
]
, "Table with final hline" =:
unlines [ "| cervisiae | domesticated |"
, "| paradoxus | wild |"
, "|--------------+--------------|"
] =?>
simpleTable' 2 mempty
[ [ plain "cervisiae", plain "domesticated" ]
, [ plain "paradoxus", plain "wild" ]
]
, "Table in a box" =:
unlines [ "|---------|---------|"
, "| static | Haskell |"
, "| dynamic | Lisp |"
, "|---------+---------|"
] =?>
simpleTable' 2 mempty
[ [ plain "static", plain "Haskell" ]
, [ plain "dynamic", plain "Lisp" ]
]
, "Table with empty cells" =:
"|||c|" =?>
simpleTable' 3 mempty [[mempty, mempty, plain "c"]]
, "Table with empty rows" =:
unlines [ "| first |"
, "| |"
, "| third |"
] =?>
simpleTable' 1 mempty [[plain "first"], [mempty], [plain "third"]]
, "Table with alignment row" =:
unlines [ "| Numbers | Text | More |"
, "| <c> | <r> | |"
, "| 1 | One | foo |"
, "| 2 | Two | bar |"
] =?>
table "" (zip [AlignCenter, AlignRight, AlignDefault] [0, 0, 0])
[]
[ [ plain "Numbers", plain "Text", plain "More" ]
, [ plain "1" , plain "One" , plain "foo" ]
, [ plain "2" , plain "Two" , plain "bar" ]
]
, "Pipe within text doesn't start a table" =:
"Ceci n'est pas une | pipe " =?>
para (spcSep [ "Ceci", "n'est", "pas", "une", "|", "pipe" ])
, "Missing pipe at end of row" =:
"|incomplete-but-valid" =?>
simpleTable' 1 mempty [ [ plain "incomplete-but-valid" ] ]
, "Table with differing row lengths" =:
unlines [ "| Numbers | Text "
, "|-"
, "| <c> | <r> |"
, "| 1 | One | foo |"
, "| 2"
] =?>
table "" (zip [AlignCenter, AlignRight] [0, 0])
[ plain "Numbers", plain "Text" ]
[ [ plain "1" , plain "One" , plain "foo" ]
, [ plain "2" ]
]
, "Table with caption" =:
unlines [ "#+CAPTION: Hitchhiker's Multiplication Table"
, "| x | 6 |"
, "| 9 | 42 |"
] =?>
table "Hitchhiker's Multiplication Table"
[(AlignDefault, 0), (AlignDefault, 0)]
[]
[ [ plain "x", plain "6" ]
, [ plain "9", plain "42" ]
]
]
, testGroup "Blocks and fragments"
[ "Source block" =:
unlines [ " #+BEGIN_SRC haskell"
, " main = putStrLn greeting"
, " where greeting = \"moin\""
, " #+END_SRC" ] =?>
let attr' = ("", ["haskell"], [])
code' = "main = putStrLn greeting\n" ++
" where greeting = \"moin\"\n"
in codeBlockWith attr' code'
, "Source block with indented code" =:
unlines [ " #+BEGIN_SRC haskell"
, " main = putStrLn greeting"
, " where greeting = \"moin\""
, " #+END_SRC" ] =?>
let attr' = ("", ["haskell"], [])
code' = "main = putStrLn greeting\n" ++
" where greeting = \"moin\"\n"
in codeBlockWith attr' code'
, "Source block with tab-indented code" =:
unlines [ "\t#+BEGIN_SRC haskell"
, "\tmain = putStrLn greeting"
, "\t where greeting = \"moin\""
, "\t#+END_SRC" ] =?>
let attr' = ("", ["haskell"], [])
code' = "main = putStrLn greeting\n" ++
" where greeting = \"moin\"\n"
in codeBlockWith attr' code'
, "Empty source block" =:
unlines [ " #+BEGIN_SRC haskell"
, " #+END_SRC" ] =?>
let attr' = ("", ["haskell"], [])
code' = ""
in codeBlockWith attr' code'
, "Source block between paragraphs" =:
unlines [ "Low German greeting"
, " #+BEGIN_SRC haskell"
, " main = putStrLn greeting"
, " where greeting = \"Moin!\""
, " #+END_SRC" ] =?>
let attr' = ("", ["haskell"], [])
code' = "main = putStrLn greeting\n" ++
" where greeting = \"Moin!\"\n"
in mconcat [ para $ spcSep [ "Low", "German", "greeting" ]
, codeBlockWith attr' code'
]
, "Source block with rundoc/babel arguments" =:
unlines [ "#+BEGIN_SRC emacs-lisp :exports both"
, "(progn (message \"Hello, World!\")"
, " (+ 23 42))"
, "#+END_SRC" ] =?>
let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
, "rundoc-block"
]
params = [ ("rundoc-language", "emacs-lisp")
, ("rundoc-exports", "both")
]
code' = unlines [ "(progn (message \"Hello, World!\")"
, " (+ 23 42))" ]
in codeBlockWith ("", classes, params) code'
, "Source block with results and :exports both" =:
unlines [ "#+BEGIN_SRC emacs-lisp :exports both"
, "(progn (message \"Hello, World!\")"
, " (+ 23 42))"
, "#+END_SRC"
, ""
, "#+RESULTS:"
, ": 65"] =?>
let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
, "rundoc-block"
]
params = [ ("rundoc-language", "emacs-lisp")
, ("rundoc-exports", "both")
]
code' = unlines [ "(progn (message \"Hello, World!\")"
, " (+ 23 42))" ]
results' = "65\n"
in codeBlockWith ("", classes, params) code'
<>
codeBlockWith ("", ["example"], []) results'
, "Source block with results and :exports code" =:
unlines [ "#+BEGIN_SRC emacs-lisp :exports code"
, "(progn (message \"Hello, World!\")"
, " (+ 23 42))"
, "#+END_SRC"
, ""
, "#+RESULTS:"
, ": 65" ] =?>
let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
, "rundoc-block"
]
params = [ ("rundoc-language", "emacs-lisp")
, ("rundoc-exports", "code")
]
code' = unlines [ "(progn (message \"Hello, World!\")"
, " (+ 23 42))" ]
in codeBlockWith ("", classes, params) code'
, "Source block with results and :exports results" =:
unlines [ "#+BEGIN_SRC emacs-lisp :exports results"
, "(progn (message \"Hello, World!\")"
, " (+ 23 42))"
, "#+END_SRC"
, ""
, "#+RESULTS:"
, ": 65" ] =?>
let results' = "65\n"
in codeBlockWith ("", ["example"], []) results'
, "Source block with results and :exports none" =:
unlines [ "#+BEGIN_SRC emacs-lisp :exports none"
, "(progn (message \"Hello, World!\")"
, " (+ 23 42))"
, "#+END_SRC"
, ""
, "#+RESULTS:"
, ": 65" ] =?>
rawBlock "html" ""
, "Source block with toggling header arguments" =:
unlines [ "#+BEGIN_SRC sh :noeval"
, "echo $HOME"
, "#+END_SRC"
] =?>
let classes = [ "bash", "rundoc-block" ]
params = [ ("rundoc-language", "sh"), ("rundoc-noeval", "yes") ]
in codeBlockWith ("", classes, params) "echo $HOME\n"
, "Example block" =:
unlines [ "#+begin_example"
, "A chosen representation of"
, "a rule."
, "#+eND_exAMPle"
] =?>
codeBlockWith ("", ["example"], [])
"A chosen representation of\na rule.\n"
, "HTML block" =:
unlines [ "#+BEGIN_HTML"
, "<aside>HTML5 is pretty nice.</aside>"
, "#+END_HTML"
] =?>
rawBlock "html" "<aside>HTML5 is pretty nice.</aside>\n"
, "Quote block" =:
unlines [ "#+BEGIN_QUOTE"
, "/Niemand/ hat die Absicht, eine Mauer zu errichten!"
, "#+END_QUOTE"
] =?>
blockQuote (para (spcSep [ emph "Niemand", "hat", "die", "Absicht,"
, "eine", "Mauer", "zu", "errichten!"
]))
, "Verse block" =:
unlines [ "The first lines of Goethe's /Faust/:"
, "#+begin_verse"
, "Habe nun, ach! Philosophie,"
, "Juristerei und Medizin,"
, "Und leider auch Theologie!"
, "Durchaus studiert, mit heißem Bemühn."
, "#+end_verse"
] =?>
mconcat
[ para $ spcSep [ "The", "first", "lines", "of"
, "Goethe's", emph "Faust" <> ":"]
, para $ mconcat
[ spcSep [ "Habe", "nun,", "ach!", "Philosophie," ]
, linebreak
, spcSep [ "Juristerei", "und", "Medizin," ]
, linebreak
, spcSep [ "Und", "leider", "auch", "Theologie!" ]
, linebreak
, spcSep [ "Durchaus", "studiert,", "mit", "heißem", "Bemühn." ]
]
]
, "Verse block with blank lines" =:
unlines [ "#+BEGIN_VERSE"
, "foo"
, ""
, "bar"
, "#+END_VERSE"
] =?>
para ("foo" <> linebreak <> linebreak <> "bar")
, "Verse block with varying indentation" =:
unlines [ "#+BEGIN_VERSE"
, " hello darkness"
, "my old friend"
, "#+END_VERSE"
] =?>
para ("\160\160hello darkness" <> linebreak <> "my old friend")
, "Raw block LaTeX" =:
unlines [ "#+BEGIN_LaTeX"
, "The category $\\cat{Set}$ is adhesive."
, "#+END_LaTeX"
] =?>
rawBlock "latex" "The category $\\cat{Set}$ is adhesive.\n"
, "Export block HTML" =:
unlines [ "#+BEGIN_export html"
, "<samp>Hello, World!</samp>"
, "#+END_export"
] =?>
rawBlock "html" "<samp>Hello, World!</samp>\n"
, "LaTeX fragment" =:
unlines [ "\\begin{equation}"
, "X_i = \\begin{cases}"
, " G_{\\alpha(i)} & \\text{if }\\alpha(i-1) = \\alpha(i)\\\\"
, " C_{\\alpha(i)} & \\text{otherwise}"
, " \\end{cases}"
, "\\end{equation}"
] =?>
rawBlock "latex"
(unlines [ "\\begin{equation}"
, "X_i = \\begin{cases}"
, " G_{\\alpha(i)} & \\text{if }\\alpha(i-1) =" ++
" \\alpha(i)\\\\"
, " C_{\\alpha(i)} & \\text{otherwise}"
, " \\end{cases}"
, "\\end{equation}"
])
, "Code block with caption" =:
unlines [ "#+CAPTION: Functor laws in Haskell"
, "#+NAME: functor-laws"
, "#+BEGIN_SRC haskell"
, "fmap id = id"
, "fmap (p . q) = (fmap p) . (fmap q)"
, "#+END_SRC"
] =?>
divWith
nullAttr
(mappend
(plain $ spanWith ("", ["label"], [])
(spcSep [ "Functor", "laws", "in", "Haskell" ]))
(codeBlockWith ("functor-laws", ["haskell"], [])
(unlines [ "fmap id = id"
, "fmap (p . q) = (fmap p) . (fmap q)"
])))
, "Convert blank lines in blocks to single newlines" =:
unlines [ "#+begin_html"
, ""
, "<span>boring</span>"
, ""
, "#+end_html"
] =?>
rawBlock "html" "\n<span>boring</span>\n\n"
, "Non-letter chars in source block parameters" =:
unlines [ "#+BEGIN_SRC C :tangle xxxx.c :city Zürich"
, "code body"
, "#+END_SRC"
] =?>
let classes = [ "c", "rundoc-block" ]
params = [ ("rundoc-language", "C")
, ("rundoc-tangle", "xxxx.c")
, ("rundoc-city", "Zürich")
]
in codeBlockWith ( "", classes, params) "code body\n"
]
, testGroup "Smart punctuation"
[ test orgSmart "quote before ellipses"
("'...hi'"
=?> para (singleQuoted "…hi"))
, test orgSmart "apostrophe before emph"
("D'oh! A l'/aide/!"
=?> para ("D’oh! A l’" <> emph "aide" <> "!"))
, test orgSmart "apostrophe in French"
("À l'arrivée de la guerre, le thème de l'«impossibilité du socialisme»"
=?> para "À l’arrivée de la guerre, le thème de l’«impossibilité du socialisme»")
, test orgSmart "Quotes cannot occur at the end of emphasized text"
("/say \"yes\"/" =?>
para ("/say" <> space <> doubleQuoted "yes" <> "/"))
, test orgSmart "Dashes are allowed at the borders of emphasis'"
("/foo---/" =?>
para (emph "foo—"))
, test orgSmart "Single quotes can be followed by emphasized text"
("Singles on the '/meat market/'" =?>
para ("Singles on the " <> (singleQuoted $ emph "meat market")))
, test orgSmart "Double quotes can be followed by emphasized text"
("Double income, no kids: \"/DINK/\"" =?>
para ("Double income, no kids: " <> (doubleQuoted $ emph "DINK")))
]
]
|