factor/extra/xmode/code2html/code2html.factor

50 lines
1.2 KiB
Factor
Raw Normal View History

2008-03-11 04:39:09 -04:00
USING: xmode.tokens xmode.marker xmode.catalog kernel html
html.elements io io.files sequences words io.encodings.utf8
namespaces ;
IN: xmode.code2html
: htmlize-tokens ( tokens -- )
[
dup token-str swap token-id [
<span word-name =class span> write </span>
] [
write
] if*
] each ;
: htmlize-line ( line-context line rules -- line-context' )
tokenize-line htmlize-tokens ;
2007-12-06 00:23:18 -05:00
: htmlize-lines ( lines mode -- )
2007-12-06 01:03:27 -05:00
f swap load-mode [ htmlize-line nl ] curry reduce drop ;
: default-stylesheet ( -- )
<style>
"extra/xmode/code2html/stylesheet.css"
resource-path utf8 file-contents write
</style> ;
2007-12-06 00:23:18 -05:00
: htmlize-stream ( path stream -- )
lines swap
<html>
<head>
default-stylesheet
<title> dup write </title>
</head>
<body>
2007-12-06 01:03:27 -05:00
<pre>
over empty?
[ 2drop ]
[ over first find-mode htmlize-lines ] if
</pre>
2007-12-06 00:23:18 -05:00
</body>
</html> ;
: htmlize-file ( path -- )
2008-03-11 04:39:09 -04:00
dup utf8 [
stdio get
over ".html" append utf8 [
htmlize-stream
] with-file-writer
] with-file-reader ;