about summary refs log tree commit diff stats
path: root/src/html.scm
diff options
context:
space:
mode:
authorCase Duckworth2024-06-03 16:56:30 -0500
committerCase Duckworth2024-06-03 16:56:30 -0500
commited4e86f47935994fb424c977e4123bde625ddff1 (patch)
treefa7e3b16c1e66741cef68d29e72b7e762ff2f8bd /src/html.scm
parentFix emit and read, add imports, fix makefile (diff)
downloadjimmy-ed4e86f47935994fb424c977e4123bde625ddff1.tar.gz
jimmy-ed4e86f47935994fb424c977e4123bde625ddff1.zip
Fix html/other sourcing; re-scramble Makefile
Diffstat (limited to 'src/html.scm')
-rw-r--r--src/html.scm58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/html.scm b/src/html.scm index 371d407..07cd921 100644 --- a/src/html.scm +++ b/src/html.scm
@@ -1,3 +1,61 @@
1(declare (module (jimmy html))) 1(declare (module (jimmy html)))
2 2
3(import scheme (chicken base)
4 (chicken irregex)
5 (jimmy emit)
6 (jimmy util))
3 7
8(define (escape-entities s)
9 (irregex-replace/all "[&<>]" s
10 (lambda (m)
11 (let ((c (irregex-match-substring m)))
12 (cond
13 ((equal? c "&") "&amp;")
14 ((equal? c "<") "&lt;")
15 ((equal? c ">") "&gt;"))))))
16
17(define (add-inline-markup s)
18 (define (char->tag ch tag)
19 (lambda (s)
20 (irregex-replace/all `(: ,ch ($ (* (~ ,ch))) ,ch) s
21 "<" tag ">" 1 "</" tag ">")))
22
23 ((o (char->tag "*" "b")
24 (char->tag "_" "i")
25 (char->tag "`" "code")) s))
26
27(formats
28 '((para (line . "~a~%")
29 (stanza . "<p>~% ~a</p>~%"))
30 (verb (line . "~a~%")
31 (stanza . "<pre><code>~a</code></pre>~%"))
32 (link (line . "<li><a href=\"~a\">~a</a></li>~%")
33 (stanza . "<ul>~% ~a</ul>~%")
34 (inline . "<a href=\"~a\">~a</a>~%"))
35 (list (line . "<li>~a</li>~%")
36 (stanza . "<ul>~% ~a</ul>~%"))
37 (quot (line . "~a~%")
38 (stanza . "<blockquote>~% ~a</blockquote>~%"))
39 (hdr1 (line . "~a")
40 (stanza . "<h1>~a</h1>~%"))
41 (hdr2 (line . "~a")
42 (stanza . "<h2>~a</h2>~%"))
43 (hdr3 (line . "~a")
44 (stanza . "<h3>~a</h3>~%"))))
45
46(filters
47 `((verb (line . ,identity)
48 (stanza . ,join-lines))
49 (link (line . ,(lambda (ln)
50 (cons (car ln)
51 ((o list
52 add-inline-markup
53 escape-entities
54 string-join)
55 (cdr ln))))))
56 (default
57 (line . ,(o list
58 add-inline-markup
59 escape-entities
60 string-join))
61 (stanza . ,string-join))))