-
Notifications
You must be signed in to change notification settings - Fork 4
/
pandoc.lfe
58 lines (46 loc) · 1.97 KB
/
pandoc.lfe
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
;;;===================================================================
;;; This file was generated by Org. Do not edit it directly.
;;; Instead, edit Lodox.org in Emacs and call org-babel-tangle.
;;;===================================================================
(defmodule pandoc
(doc "A partial LFE port of [Pandex][].
[Pandex]: https://github.com/FilterKaapi/pandex")
(export all))
(include-lib "clj/include/compose.lfe")
(defun convert-string (string)
"Equivalent to `(`[[convert-string/3]]` string \"markdown_github\" \"html\")`."
(convert-string string "markdown_github" "html"))
(defun convert-string (string from to)
"Equivalent to `(`[[convert-string/4]]` string from to [])`."
(convert-string string from to []))
(defun convert-string (string from to _options)
(let ((dot-temp ".temp"))
(if (filelib:is_dir dot-temp) 'ok (file:make_dir dot-temp))
(let ((name (filename:join dot-temp (random-name))))
(file:write_file name string)
(let ((`#(ok ,output) (convert-file name from to)))
(file:delete name)
`#(ok ,output)))))
(defun convert-file (file)
"Equivalent to `(`[[convert-file/3]]` file \"markdown_github\" \"html\")`."
(convert-file file "markdown" "html"))
(defun convert-file (file from to)
"Equivalent to `(`[[convert-file/4]]` file from to [])`."
(convert-file file from to []))
(defun convert-file (file from to _options)
"[[convert-file/4]] works under the hood of all the other functions."
(let ((output (os:cmd (++ "pandoc " file " -f " from " -t " to))))
`#(ok ,output)))
(defun random-name ()
(++ (random-string) "-" (timestamp) ".md"))
(defun random-string ()
(random:seed (erlang:monotonic_time)
(erlang:time_offset)
(erlang:unique_integer))
(-> #0x100000000000000
(random:uniform)
(integer_to_list 36)
(string:to_lower)))
(defun timestamp ()
(let ((`#(,megasec ,sec ,_microsec) (os:timestamp)))
(-> (* megasec 1000000) (+ sec) (integer_to_list))))