From 22c3f2da96853b3b1a36efe6766cf643545848b7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 2 Jul 2023 14:32:26 -0500 Subject: Add scratchdown --- scratchdown.scm | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 scratchdown.scm (limited to 'scratchdown.scm') diff --git a/scratchdown.scm b/scratchdown.scm new file mode 100755 index 0000000..2775e3f --- /dev/null +++ b/scratchdown.scm @@ -0,0 +1,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)) -- cgit 1.4.1-21-gabe81