factor/basis/lcs/diff2html/diff2html.factor

41 lines
938 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.
USING: accessors kernel lcs sequences strings xml.syntax
xml.writer ;
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-CHUNK[[ <td class="retain"><-></td> ]]
dup XML-CHUNK[[ <tr><-><-></tr> ]] ;
2008-05-27 01:02:16 -04:00
M: insert diff-line
item-string XML-CHUNK[[
<tr>
<td> </td>
<td class="insert"><-></td>
</tr>
]] ;
2008-05-27 01:02:16 -04:00
M: delete diff-line
item-string XML-CHUNK[[
<tr>
<td class="delete"><-></td>
<td> </td>
</tr>
]] ;
2008-05-27 01:02:16 -04:00
: htmlize-diff ( diff -- xml )
[ diff-line ] map
XML-CHUNK[[
<table width="100%" class="comparison">
<tr><th>Old</th><th>New</th></tr>
<->
</table>
]] ;