1 USING: xmode.tokens xmode.marker xmode.catalog kernel locals
2 html.elements io io.files sequences words io.encodings.utf8
3 namespaces xml.entities accessors xml.interpolate locals xml.writer ;
6 : htmlize-tokens ( tokens -- xml )
8 [ str>> ] [ id>> ] bi [
10 [XML <span class=<->><-></span> XML]
14 : htmlize-line ( line-context line rules -- line-context' xml )
15 tokenize-line htmlize-tokens ;
17 : htmlize-lines ( lines mode -- xml )
18 [ f ] 2dip load-mode [ htmlize-line ] curry map nip ;
20 : default-stylesheet ( -- xml )
21 "resource:basis/xmode/code2html/stylesheet.css"
23 [XML <style><-></style> XML] ;
25 :: htmlize-stream ( path stream -- xml )
27 [ "" ] [ first find-mode path swap htmlize-lines ]
29 default-stylesheet :> stylesheet
33 <title><-path-></title>
40 : htmlize-file ( path -- )
42 dup ".html" append utf8 [
43 input-stream get htmlize-stream write-xml