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.
|
2015-08-12 09:49:02 -04:00
|
|
|
USING: accessors kernel lcs sequences strings xml.syntax
|
|
|
|
xml.writer ;
|
2008-05-27 01:02:16 -04:00
|
|
|
IN: lcs.diff2html
|
|
|
|
|
2009-01-27 01:03:42 -05:00
|
|
|
GENERIC: diff-line ( obj -- xml )
|
2008-05-27 01:02:16 -04:00
|
|
|
|
2009-01-27 01:03:42 -05:00
|
|
|
: item-string ( item -- string )
|
2017-08-26 13:27:25 -04:00
|
|
|
item>> [ char: no-break-space 1string ] when-empty ;
|
2008-05-27 01:02:16 -04:00
|
|
|
|
|
|
|
M: retain diff-line
|
2009-01-27 01:03:42 -05:00
|
|
|
item-string
|
2017-08-26 18:17:24 -04:00
|
|
|
XML-CHUNK[[ <td class="retain"><-></td> ]]
|
|
|
|
dup XML-CHUNK[[ <tr><-><-></tr> ]] ;
|
2008-05-27 01:02:16 -04:00
|
|
|
|
|
|
|
M: insert diff-line
|
2017-08-26 18:17:24 -04:00
|
|
|
item-string XML-CHUNK[[
|
2009-01-27 01:03:42 -05:00
|
|
|
<tr>
|
|
|
|
<td> </td>
|
|
|
|
<td class="insert"><-></td>
|
|
|
|
</tr>
|
2017-08-26 18:17:24 -04:00
|
|
|
]] ;
|
2008-05-27 01:02:16 -04:00
|
|
|
|
|
|
|
M: delete diff-line
|
2017-08-26 18:17:24 -04:00
|
|
|
item-string XML-CHUNK[[
|
2009-01-27 01:03:42 -05:00
|
|
|
<tr>
|
|
|
|
<td class="delete"><-></td>
|
|
|
|
<td> </td>
|
|
|
|
</tr>
|
2017-08-26 18:17:24 -04:00
|
|
|
]] ;
|
2008-05-27 01:02:16 -04:00
|
|
|
|
2009-01-27 01:03:42 -05:00
|
|
|
: htmlize-diff ( diff -- xml )
|
|
|
|
[ diff-line ] map
|
2017-08-26 18:17:24 -04:00
|
|
|
XML-CHUNK[[
|
2009-01-27 01:03:42 -05:00
|
|
|
<table width="100%" class="comparison">
|
|
|
|
<tr><th>Old</th><th>New</th></tr>
|
|
|
|
<->
|
|
|
|
</table>
|
2017-08-26 18:17:24 -04:00
|
|
|
]] ;
|