-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathcode2html.factor
More file actions
45 lines (39 loc) · 1.22 KB
/
Copy pathcode2html.factor
File metadata and controls
45 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
USING: accessors io io.encodings.utf8 io.files kernel namespaces
sequences xml.syntax xml.writer xmode.catalog xmode.marker ;
IN: xmode.code2html
: htmlize-tokens ( tokens -- xml )
[
[ str>> ] [ id>> ] bi [
name>> swap
[XML <span class=<->><-></span> XML]
] when*
] map ;
: htmlize-line ( line-context line rules -- line-context' xml )
tokenize-line htmlize-tokens ;
: htmlize-lines ( lines mode -- xml )
[ f ] 2dip load-mode [ htmlize-line ] curry map nip
{ "\n" } join ;
: default-stylesheet ( -- xml )
"resource:basis/xmode/code2html/stylesheet.css"
utf8 file-contents
[XML <style><-></style> XML] ;
:: htmlize-stream ( path stream -- xml )
stream stream-lines
[ "" ] [ path over first find-mode htmlize-lines ]
if-empty :> input
default-stylesheet :> stylesheet
<XML <!DOCTYPE html> <html>
<head>
<-stylesheet->
<title><-path-></title>
</head>
<body>
<pre><-input-></pre>
</body>
</html> XML> ;
: htmlize-file ( path -- )
dup utf8 [
dup ".html" append utf8 [
input-stream get htmlize-stream write-xml
] with-file-writer
] with-file-reader ;