#!/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))