diff options
author | Case Duckworth | 2023-07-02 14:32:26 -0500 |
---|---|---|
committer | Case Duckworth | 2023-07-02 14:32:26 -0500 |
commit | 22c3f2da96853b3b1a36efe6766cf643545848b7 (patch) | |
tree | 3a24f9dfebae9b56fdcab9c2567cbb6e9cc14e86 /scratchdown.scm | |
parent | Add dependencies section (diff) | |
download | chicken-scratch-22c3f2da96853b3b1a36efe6766cf643545848b7.tar.gz chicken-scratch-22c3f2da96853b3b1a36efe6766cf643545848b7.zip |
Add scratchdown main
Diffstat (limited to 'scratchdown.scm')
-rwxr-xr-x | scratchdown.scm | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/scratchdown.scm b/scratchdown.scm new file mode 100755 index 0000000..2775e3f --- /dev/null +++ b/scratchdown.scm | |||
@@ -0,0 +1,55 @@ | |||
1 | #!/bin/sh | ||
2 | #| -*- scheme -*- | ||
3 | exec csi -s "$0" "$@" | ||
4 | SCRATCHDOWN --- Combine markdown and chicken-scratch | ||
5 | |# | ||
6 | |||
7 | (import (chicken io) | ||
8 | (chicken irregex) | ||
9 | (chicken process-context) | ||
10 | (chicken-scratch) | ||
11 | (html-parser) | ||
12 | (lowdown) | ||
13 | (sxml-transforms) | ||
14 | (utf8)) | ||
15 | |||
16 | (define (expand* text) | ||
17 | (expand-string | ||
18 | (irregex-replace/all '(or (: #\# #\# (look-ahead (or #\{ #\())) | ||
19 | (: #\# (look-ahead (~ #\{ #\())) | ||
20 | (: #\# eos)) | ||
21 | text | ||
22 | "##"))) | ||
23 | |||
24 | #;(define (list-of-strings? xs) | ||
25 | (cond | ||
26 | ((null? xs) #t) | ||
27 | ((not (string? (car xs))) #f) | ||
28 | (else (list-of-strings? (cdr xs))))) | ||
29 | |||
30 | #;(define (expand-text x) | ||
31 | (print x) | ||
32 | (cond | ||
33 | ((symbol? x) x) | ||
34 | ((string? x) | ||
35 | (expand* x)) | ||
36 | ((list-of-strings? x) | ||
37 | (expand* (apply string-append x))) | ||
38 | ((list-of-strings? (cdr x)) | ||
39 | (cons (car x) | ||
40 | (expand-text (cdr x)))) | ||
41 | ((list? x) | ||
42 | (map expand-text x)) | ||
43 | (else x))) | ||
44 | |||
45 | (define (read-and-expand file) | ||
46 | (let* ((text (with-input-from-file file read-string)) | ||
47 | (expd (irregex-replace "^#!.*\n" (expand* text) "")) | ||
48 | #;(sexp (markdown->sxml expd)) | ||
49 | ) | ||
50 | (markdown->html expd))) | ||
51 | |||
52 | (define (main args) | ||
53 | (for-each read-and-expand args)) | ||
54 | |||
55 | (main (command-line-arguments)) | ||