2007-11-28 23:34:11 -05:00
|
|
|
USING: xmode.tokens xmode.marker
|
|
|
|
xmode.catalog kernel html html.elements io io.files
|
|
|
|
sequences words ;
|
|
|
|
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 -- )
|
|
|
|
<pre>
|
|
|
|
f swap load-mode [ htmlize-line nl ] curry reduce drop
|
|
|
|
</pre> ;
|
2007-11-28 23:34:11 -05:00
|
|
|
|
|
|
|
: default-stylesheet ( -- )
|
|
|
|
<style>
|
|
|
|
"extra/xmode/code2html/stylesheet.css"
|
|
|
|
resource-path <file-reader> 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>
|
|
|
|
over empty?
|
|
|
|
[ 2drop ]
|
|
|
|
[ over first find-mode htmlize-lines ] if
|
|
|
|
</body>
|
|
|
|
</html> ;
|
|
|
|
|
2007-11-28 23:34:11 -05:00
|
|
|
: htmlize-file ( path -- )
|
2007-12-06 00:23:18 -05:00
|
|
|
dup <file-reader> over ".html" append <file-writer>
|
|
|
|
[ htmlize-stream ] with-stream ;
|