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 ;
|
2007-11-28 23:34:11 -05:00
|
|
|
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 ;
|
2007-11-28 23:34:11 -05:00
|
|
|
|
|
|
|
: default-stylesheet ( -- )
|
|
|
|
<style>
|
|
|
|
"extra/xmode/code2html/stylesheet.css"
|
2008-02-16 23:17:41 -05:00
|
|
|
resource-path utf8 file-contents write
|
2007-11-28 23:34:11 -05:00
|
|
|
</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> ;
|
|
|
|
|
2007-11-28 23:34:11 -05:00
|
|
|
: 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 ;
|