cripslock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit a0d36ba5d28b8c2aab88b69a5d3c68230dbd391e
parent fa8b9f9c8df7c9b44a8a7cdbace1dd087a2dc216
Author: Daniel Barlow <dan@telent.net>
Date:   Fri, 18 Jul 2025 16:51:56 +0100

connect all the bits

Diffstat:
Atests/blog.textile | 16++++++++++++++++
Atests/hello.txt | 1+
Mtextile.fnl | 45++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/tests/blog.textile b/tests/blog.textile @@ -0,0 +1,16 @@ +h1. header 1 + +This is the first para + +* item 1 +# subitem + +This is the second para + +bq. this block is quoted + +pre. +line one +line 2 +hello + diff --git a/tests/hello.txt b/tests/hello.txt @@ -0,0 +1 @@ +hello world diff --git a/textile.fnl b/textile.fnl @@ -251,5 +251,48 @@ ) +(fn parse-stream [stream] + (icollect [p (read-blocks stream)] + (let [(tag body) (tag-and-body p)] + (cons-tag tag (extract-lists body))))) + +(fn to-html [out-stream el] + (if (= (type el) :string) + (out-stream:write el) + (let [[tag & content] el] + (out-stream:write (string.format "<%s>" tag)) + (each [_ child (ipairs content)] + (to-html out-stream child)) + (out-stream:write (string.format "</%s>" tag))))) + + +(define-tests :parse-stream + (fn convert [name] + (with-open [f (io.open name :r)] + (with-open [out (assert (io.tmpfile))] + (each [_ el (ipairs (parse-stream f))] + (to-html out el)) + (out:seek :set 0) + (out:read "*a")))) + + (expect= (convert "tests/hello.txt") "<p>hello world\n</p>") + (expect= (convert "tests/blog.textile") + "<h1>header 1 +</h1><p>This is the first para +</p><p><ul><li>item 1 +<ol><li>subitem +</li></ol></li></ul></p><p>This is the second para +</p><blockquote>this block is quoted +</blockquote><pre> +line one +line 2 +hello +</pre>") -{} + ) + + +{ + :parse parse-stream + : to-html + }