|
15 | 15 | (defparameter *pandoc-path* (or (uiop:getenv "PANDOC_PATH")
|
16 | 16 | "pandoc"))
|
17 | 17 |
|
18 |
| -(defparameter *emacs-path* (or (uiop:getenv "EMACS_PATH") |
19 |
| - "emacs")) |
20 |
| - |
21 | 18 | (defun which (command)
|
22 | 19 | (handler-case
|
23 | 20 | (let* ((result (with-output-to-string (s)
|
|
40 | 37 | (or (which command)
|
41 | 38 | (error "Requiement ~S does not exist. Ensure if it's installed and check your PATH." command))))
|
42 | 39 |
|
43 |
| -(defun convert-readme (file) |
| 40 | +(defun pandoc (file &key (from "markdown") (to "html")) |
44 | 41 | (check-type file pathname)
|
45 | 42 | (assert (uiop:file-exists-p file))
|
46 |
| - (let ((type (pathname-type file))) |
47 |
| - (cond |
48 |
| - ((or (null type) |
49 |
| - (string= type "txt")) |
50 |
| - (convert-plaintext-into-html file)) |
51 |
| - ((or (string= type "markdown") |
52 |
| - (string= type "md")) |
53 |
| - (convert-markdown-into-html file)) |
54 |
| - ((string= type "org") |
55 |
| - (convert-org-into-html file))))) |
56 |
| - |
57 |
| -(defun convert-plaintext-into-html (file) |
58 |
| - (concatenate 'string "<pre>" (uiop:read-file-string file) "</pre>")) |
59 |
| - |
60 |
| -(defun convert-markdown-into-html (file) |
61 | 43 | (check-if-command-installed *timeout-command* *pandoc-path*)
|
62 |
| - (ignore-some-conditions (uiop:subprocess-error) |
63 |
| - (with-output-to-string (s) |
64 |
| - (uiop:run-program `(,*timeout-command* 10 ,*pandoc-path* ,(namestring file)) |
65 |
| - :force-shell t |
66 |
| - :output s |
67 |
| - :error-output *error-output*)))) |
| 44 | + (with-output-to-string (s) |
| 45 | + (uiop:run-program `(,*timeout-command* "10" ,*pandoc-path* "-f" ,from "-t" ,to ,(namestring (probe-file file))) |
| 46 | + :force-shell t |
| 47 | + :output s |
| 48 | + :error-output *error-output*))) |
68 | 49 |
|
69 |
| -(defun convert-org-into-html (file) |
70 |
| - (check-if-command-installed *timeout-command* *emacs-path*) |
71 |
| - (ignore-some-conditions (uiop:subprocess-error) |
72 |
| - (with-output-to-string (s) |
73 |
| - (uiop:run-program `(,*timeout-command* |
74 |
| - 10 |
75 |
| - ,*emacs-path* "-Q" "-batch" "--file" ,(namestring file) |
76 |
| - "--eval" "(setq org-export-with-toc nil)" |
77 |
| - "--eval" "(princ (org-export-as-html 3 nil 'string t))") |
78 |
| - :force-shell t |
79 |
| - :output s |
80 |
| - :error-output *error-output*)))) |
| 50 | +(defun convert-readme (file) |
| 51 | + (check-type file pathname) |
| 52 | + (let ((type (pathname-type file))) |
| 53 | + (ignore-some-conditions (uiop:subprocess-error) |
| 54 | + (cond |
| 55 | + ((or (string= type "markdown") |
| 56 | + (string= type "md")) |
| 57 | + (pandoc file :from "markdown")) |
| 58 | + ((string= type "org") |
| 59 | + (pandoc file :from "org")))))) |
0 commit comments