factor/basis/lcs/diff2html/diff2html.factor

43 lines
991 B
Factor
Raw Normal View History

2010-01-14 10:10:13 -05:00
! Copyright (C) 2008, 2010 Slava Pestov
2008-05-27 01:02:16 -04:00
! See http://factorcode.org/license.txt for BSD license.
2009-02-05 22:17:03 -05:00
USING: lcs xml.syntax xml.writer kernel strings ;
2008-05-27 01:02:16 -04:00
FROM: accessors => item>> ;
FROM: io => write ;
FROM: sequences => each if-empty when-empty map ;
2008-05-27 01:02:16 -04:00
IN: lcs.diff2html
GENERIC: diff-line ( obj -- xml )
2008-05-27 01:02:16 -04:00
: item-string ( item -- string )
item>> [ CHAR: no-break-space 1string ] when-empty ;
2008-05-27 01:02:16 -04:00
M: retain diff-line
item-string
[XML <td class="retain"><-></td> XML]
dup [XML <tr><-><-></tr> XML] ;
2008-05-27 01:02:16 -04:00
M: insert diff-line
item-string [XML
<tr>
<td> </td>
<td class="insert"><-></td>
</tr>
XML] ;
2008-05-27 01:02:16 -04:00
M: delete diff-line
item-string [XML
<tr>
<td class="delete"><-></td>
<td> </td>
</tr>
XML] ;
2008-05-27 01:02:16 -04:00
: htmlize-diff ( diff -- xml )
[ diff-line ] map
[XML
<table width="100%" class="comparison">
<tr><th>Old</th><th>New</th></tr>
<->
</table>
XML] ;