-
Notifications
You must be signed in to change notification settings - Fork 0
/
pandoc.zp
59 lines (52 loc) · 2.08 KB
/
pandoc.zp
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
(module "pandoc"
(export
`("get-readers" ,readers)
`("get-writers" ,writers)
`("convert" ,convert)
`("get-formats" ,formats)
`("write" ,_write))
(loads "pandoc/priv/Pandoc" "pandoc/priv/req")
(MATCHERS
#{"md" #{:ext "markdown" :binary #f}
"tex" #{:ext "latex" :binary #f}
"html" #{:ext "html" :binary #f}
"json" #{:ext "json" :binary #f}
"org" #{:ext "org" :binary #f}
"tei" #{:ext "tei" :binary #f}
"t2t" #{:ext "t2t" :binary #t}
"docx" #{:ext "docx" :binary #t}
"odt" #{:ext "odt" :binary #t}
"epub" #{:ext "epub" :binary #t}
"groff" #{:ext "man" :binary #f}
"rst" #{:ext "rst" :binary #f}
"rtf" #{:ext "rtf" :binary #f}
"txt" #{:ext "plain" :binary #f}
"asciidoc" #{:ext "asciidoc" :binary #f}
"adoc" #{:ext "asciidoc" :binary #f}
"wiki" #{:ext "mediawiki" :binary #f}
"lhs" #{:ext "haddock" :binary #f}})
(formats (lambda ()
"get all available pandoc formats (read and write).
complexity: O(n)
returns: a list of strings"
(set:get-elems (set:set (++ (readers) (writers)) :container-type '[]))))
(filetype (lambda (filename)
(let ((extension (list:last (string:split filename #\.))))
(if (in? MATCHERS extension)
(MATCHERS extension)
(error:from-string (++ "Unknown file type: " extension))))))
(_write (lambda (from to)
"converts based on an input and output file. Does file extension
matching.
params:
- from: input file
- to: output file
complexity: varies based on formats
returns: nil"
(let* ((fft (filetype from))
(inpt ((if (fft :binary) read-binary-contents read-contents)
from))
(writer (curry write (convert (fft :ext)
((filetype to) :ext)
inpt))))
(with-output-file to writer)))))