| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  | USING: xmode.tokens xmode.marker xmode.catalog kernel locals | 
					
						
							| 
									
										
										
										
											2009-01-30 20:28:16 -05:00
										 |  |  | io io.files sequences words io.encodings.utf8 | 
					
						
							| 
									
										
										
										
											2009-02-05 22:17:03 -05:00
										 |  |  | namespaces xml.entities accessors xml.syntax locals xml.writer ;
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | IN: xmode.code2html | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  | : htmlize-tokens ( tokens -- xml )
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2008-06-01 18:22:39 -04:00
										 |  |  |         [ str>> ] [ id>> ] bi [ | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  |             name>> swap
 | 
					
						
							|  |  |  |             [XML <span class=<->><-></span> XML] | 
					
						
							| 
									
										
										
										
											2009-01-30 20:34:31 -05:00
										 |  |  |         ] when*
 | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  |     ] map ;
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  | : htmlize-line ( line-context line rules -- line-context' xml )
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  |     tokenize-line htmlize-tokens ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  | : htmlize-lines ( lines mode -- xml )
 | 
					
						
							| 
									
										
										
										
											2009-01-31 04:02:10 -05:00
										 |  |  |     [ f ] 2dip load-mode [ htmlize-line ] curry map nip
 | 
					
						
							|  |  |  |     { "\n" } join ;
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  | : default-stylesheet ( -- xml )
 | 
					
						
							|  |  |  |     "resource:basis/xmode/code2html/stylesheet.css" | 
					
						
							|  |  |  |     utf8 file-contents | 
					
						
							|  |  |  |     [XML <style><-></style> XML] ;
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  | :: htmlize-stream ( path stream -- xml )
 | 
					
						
							|  |  |  |     stream lines
 | 
					
						
							| 
									
										
										
										
											2009-01-30 20:34:31 -05:00
										 |  |  |     [ "" ] [ path over first find-mode htmlize-lines ] | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  |     if-empty :> input | 
					
						
							|  |  |  |     default-stylesheet :> stylesheet | 
					
						
							|  |  |  |     <XML <html> | 
					
						
							| 
									
										
										
										
											2007-12-06 00:23:18 -05:00
										 |  |  |         <head> | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  |             <-stylesheet-> | 
					
						
							|  |  |  |             <title><-path-></title> | 
					
						
							| 
									
										
										
										
											2007-12-06 00:23:18 -05:00
										 |  |  |         </head> | 
					
						
							|  |  |  |         <body> | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  |             <pre><-input-></pre> | 
					
						
							| 
									
										
										
										
											2007-12-06 00:23:18 -05:00
										 |  |  |         </body> | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  |     </html> XML> ;
 | 
					
						
							| 
									
										
										
										
											2007-12-06 00:23:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-28 23:34:11 -05:00
										 |  |  | : htmlize-file ( path -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-11 04:39:09 -04:00
										 |  |  |     dup utf8 [ | 
					
						
							| 
									
										
										
										
											2008-05-05 03:19:25 -04:00
										 |  |  |         dup ".html" append utf8 [ | 
					
						
							| 
									
										
										
										
											2009-01-26 22:38:36 -05:00
										 |  |  |             input-stream get htmlize-stream write-xml | 
					
						
							| 
									
										
										
										
											2008-03-11 04:39:09 -04:00
										 |  |  |         ] with-file-writer | 
					
						
							|  |  |  |     ] with-file-reader ;
 |