about summary refs log tree commit diff stats
path: root/scratchdown.scm
blob: 2775e3f6a3f3d2065a88c54b602eb4a135706cef (plain)
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
#!/bin/sh
#| -*- scheme -*-
exec csi -s "$0" "$@"
SCRATCHDOWN --- Combine markdown and chicken-scratch
|#

(import (chicken io)
        (chicken irregex)
        (chicken process-context)
        (chicken-scratch)
        (html-parser)
        (lowdown)
        (sxml-transforms)
        (utf8))

(define (expand* text)
  (expand-string
   (irregex-replace/all '(or (: #\# #\# (look-ahead (or #\{ #\()))
                             (: #\# (look-ahead (~ #\{ #\()))
                             (: #\# eos))
                        text
                        "##")))

#;(define (list-of-strings? xs)
  (cond
   ((null? xs) #t)
   ((not (string? (car xs))) #f)
   (else (list-of-strings? (cdr xs)))))

#;(define (expand-text x)
  (print x)
  (cond
   ((symbol? x) x)
   ((string? x)
    (expand* x))
   ((list-of-strings? x)
    (expand* (apply string-append x)))
   ((list-of-strings? (cdr x))
    (cons (car x)
          (expand-text (cdr x))))
   ((list? x)
    (map expand-text x))
   (else x)))

(define (read-and-expand file)
  (let* ((text (with-input-from-file file read-string))
         (expd (irregex-replace "^#!.*\n" (expand* text) ""))
         #;(sexp (markdown->sxml expd))
         )
    (markdown->html expd)))

(define (main args)
  (for-each read-and-expand args))

(main (command-line-arguments))