<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>examples/diff.git</filename>
    </added>
    <added>
      <filename>examples/diff.svn</filename>
    </added>
    <added>
      <filename>examples/test_git_diff.rb</filename>
    </added>
    <added>
      <filename>examples/test_svn_diff.rb</filename>
    </added>
    <added>
      <filename>nbproject/project.properties</filename>
    </added>
    <added>
      <filename>nbproject/project.xml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -17,19 +17,17 @@ things to improve, so contribution/patches are very welcome.
   to copy it to your project's dir to use it.
 * To use in Rails project:
 
-   require 'diff_to_html'
-   ...
-   converter = DiffToHtml.new
-   ...
+    require 'diff_to_html'
+    diff = `cat #{File.join(File.dirname(__FILE__), 'diff.svn')}`
+    converter = SvnDiffToHtml.new #there's also GitDiffToHtml
+    puts converter.composite_to_html(diff)
 
 * to use in any Ruby program:
    
-   require 'rubygems'
-   require 'diff_to_html'
-   ...
-
-(just like in test.rb)
-   
+    require 'rubygems'
+    require 'diff_to_html'
+    ...
+  
 == License
 
 diff_to_html is released under the MIT license.</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 Gem::Specification.new do |s|
   s.name = 'diff_to_html'
-  s.version = '1.0.2'
+  s.version = '1.0.3'
   s.date = '2008-05-23'
   
   s.summary = &quot;Unified diff to HTML converter&quot;
@@ -15,5 +15,5 @@ Gem::Specification.new do |s|
   s.rdoc_options &lt;&lt; '--inline-source' &lt;&lt; '--charset=UTF-8'
   s.extra_rdoc_files = ['README.rdoc']
   
-  s.files = %w(lib/diff_to_html.rb examples/diff.css examples/test.rb examples/test.sh lib README.rdoc)
+  s.files = %w(lib/diff_to_html.rb examples/diff.css examples/diff.git examples/diff.svn examples/test_git_diff.rb examples/test_svn_diff.rb examples/test.rb examples/test.sh lib README.rdoc)
 end
\ No newline at end of file</diff>
      <filename>diff_to_html.rb.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -1,68 +1,75 @@
-ul.diff {
-  padding:0;
-}
-
-.diff table col.lineno {
-  width:4em;
-}
-
-.diff h2, .diff h2 a {
-  color:#333333;
-  font-size:14px;
-  letter-spacing:normal;
-  margin:0pt auto;
-}
-
-.diff h2 {
-  padding:0.1em 0pt 0.25em 0.5em;
-}
-
-table.diff {
-  font-size : 9pt;
-  font-family : &quot;lucida console&quot;, &quot;courier new&quot;, monospace;
-  white-space : pre;
-  border : 1px solid #D7D7D7;
-  border-collapse : collapse;
-  line-height : 110%;
-  width: 100%;  
-}  
-
-.diff tr {
-  background: white;
-}
-
-.diff td {
-  border : none;
-  padding : 0px 10px;
-  margin : 0px;
-}
-
-.diff td a {
-  text-decoration: none;
-}
-
-tr.a { background : #ddffdd; }
-
-tr.r { background : #ffdddd; }
-
-tr.range { background : #EAF2F5; color : #999; }
-
-td.ln {
-  background : #ECECEC; 
-  color : #aaa;
-  border-top:1px solid #999988;
-  border-bottom:1px solid #999988;
-  border-right:1px solid #D7D7D7;
-}
-
-.diff li {
-  background:#F7F7F7 none repeat scroll 0%;
-  border:1px solid #D7D7D7;
-  list-style-type:none;
-  margin:0pt 0pt 2em;
-  padding:2px;
-}
-
-.ln a {
-  color: #aaa;
+body, p, ol, ul, td {
+  font-family:verdana,arial,helvetica,sans-serif;
+  font-size:13px;
+}
+
+a, a:link, a:visited {
+color:#507EC0;
+text-decoration:none;
+}
+
+ul.diff {
+  padding:0;
+}
+
+.diff table col.lineno {
+  width:4em;
+}
+
+.diff h2 {
+  color:#333333;
+  font-size:14px;
+  letter-spacing:normal;
+  margin:0pt auto;
+  padding:0.1em 0pt 0.25em 0.5em;
+}
+
+table.diff {
+  font-size : 9pt;
+  font-family : &quot;lucida console&quot;, &quot;courier new&quot;, monospace;
+  white-space : pre;
+  border : 1px solid #D7D7D7;
+  border-collapse : collapse;
+  line-height : 110%;
+  width: 100%;  
+}  
+
+.diff tr {
+  background: white;
+}
+
+.diff td {
+  border : none;
+  padding : 0px 10px;
+  margin : 0px;
+}
+
+.diff td a {
+  text-decoration: none;
+}
+
+tr.a { background : #ddffdd; }
+
+tr.r { background : #ffdddd; }
+
+tr.range { background : #EAF2F5; color : #999; }
+
+td.ln {
+  background : #ECECEC; 
+  color : #aaa;
+  border-top:1px solid #999988;
+  border-bottom:1px solid #999988;
+  border-right:1px solid #D7D7D7;
+}
+
+.diff li {
+  background:#F7F7F7 none repeat scroll 0%;
+  border:1px solid #D7D7D7;
+  list-style-type:none;
+  margin:0pt 0pt 2em;
+  padding:2px;
+}
+
+.ln a {
+  color: #aaa;
 }
\ No newline at end of file</diff>
      <filename>examples/diff.css</filename>
    </modified>
    <modified>
      <diff>@@ -1,18 +1,94 @@
-require 'rubygems'
-require 'diff_to_html'
-#require '../lib/diff_to_html.rb'
-diff = `svn diff -r 46:47 svn://hamptoncatlin.com/haml --diff-cmd diff -x &quot;-U 2&quot;`
-#diff = `cat diff`
-puts &lt;&lt;EOF
-&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
-&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;DTD/xhtml1-transitional.dtd&quot;&gt;
-&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot; xml:lang=&quot;en&quot;&gt;
-&lt;head&gt;
-  &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;diff.css&quot;&gt;
-  &lt;title&gt;diff of HAML revision 47&lt;/title&gt;
-&lt;/head&gt;
-&lt;body&gt;
-#{DiffToHtml.new.get_diff(diff)}
-&lt;/body&gt;
-&lt;/html&gt;
-EOF
\ No newline at end of file
+def out(diff, converter, title)
+  puts &lt;&lt;-EOF
+  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;DTD/xhtml1-transitional.dtd&quot;&gt;
+  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot; xml:lang=&quot;en&quot;&gt;
+  &lt;head&gt;
+    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;/&gt;
+    &lt;title&gt;#{title}&lt;/title&gt;
+    &lt;style type=&quot;text/css&quot;&gt;
+      &lt;!-- 
+      body, p, ol, ul, td {
+        font-family:verdana,arial,helvetica,sans-serif;
+        font-size:13px;
+      }
+
+      a, a:link, a:visited {
+      color:#507EC0;
+      text-decoration:none;
+      }
+
+      ul.diff {
+        padding:0;
+      }
+
+      .diff table col.lineno {
+        width:4em;
+      }
+
+      .diff h2 {
+        color:#333333;
+        font-size:14px;
+        letter-spacing:normal;
+        margin:0pt auto;
+        padding:0.1em 0pt 0.25em 0.5em;
+      }
+
+      table.diff {
+        font-size : 9pt;
+        font-family : &quot;lucida console&quot;, &quot;courier new&quot;, monospace;
+        white-space : pre;
+        border : 1px solid #D7D7D7;
+        border-collapse : collapse;
+        line-height : 110%;
+        width: 100%;  
+      }  
+
+      .diff tr {
+        background: white;
+      }
+
+      .diff td {
+        border : none;
+        padding : 0px 10px;
+        margin : 0px;
+      }
+
+      .diff td a {
+        text-decoration: none;
+      }
+
+      tr.a { background : #ddffdd; }
+
+      tr.r { background : #ffdddd; }
+
+      tr.range { background : #EAF2F5; color : #999; }
+
+      td.ln {
+        background : #ECECEC; 
+        color : #aaa;
+        border-top:1px solid #999988;
+        border-bottom:1px solid #999988;
+        border-right:1px solid #D7D7D7;
+      }
+
+      .diff li {
+        background:#F7F7F7 none repeat scroll 0%;
+        border:1px solid #D7D7D7;
+        list-style-type:none;
+        margin:0pt 0pt 2em;
+        padding:2px;
+      }
+
+      .ln a {
+        color: #aaa;
+      }
+      --&gt; 
+    &lt;/style&gt;
+  &lt;/head&gt;
+  &lt;body&gt;
+  #{converter.composite_to_html(diff)}
+  &lt;/body&gt;
+  &lt;/html&gt;
+  EOF
+end</diff>
      <filename>examples/test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,10 +3,6 @@ require 'cgi'
 class DiffToHtml
 
   attr_accessor :file_prefix
-  
-  #
-  # globals
-  #
 
   def ln_cell(ln, side = nil)
     anchor = &quot;f#{@filenum}#{side}#{ln}&quot;
@@ -17,10 +13,10 @@ class DiffToHtml
     result += &quot;&lt;/td&gt;&quot;
     result
   end
+
   #
   # helper for building the next row in the diff
   #
-
   def get_diff_row(left_ln, right_ln)
     result = []
     if @left.length &gt; 0 or @right.length &gt; 0
@@ -56,10 +52,6 @@ class DiffToHtml
     return result.join(&quot;\n&quot;), left_ln, right_ln
   end
 
-  #
-  # build the diff
-  #
-
   def range_row(range)
     &quot;&lt;tr class='range'&gt;&lt;td&gt;...&lt;/td&lt;td&gt;...&lt;/td&gt;&lt;td&gt;#{range}&lt;/td&gt;&lt;/tr&gt;&quot;
   end
@@ -72,16 +64,14 @@ class DiffToHtml
   end
 
   def begin_file(file)
-    @filenum ||=0
     result = &lt;&lt;EOF 
-&lt;li&gt;&lt;h2&gt;&lt;a name=&quot;F#{@filenum}&quot; href=&quot;#F#{@filenum}&quot;&gt;#{@file_prefix}#{file}&lt;/a&gt;&lt;/h2&gt;&lt;table class='diff'&gt;
+&lt;li&gt;&lt;h2&gt;&lt;a name=&quot;F#{@filenum}&quot; href=&quot;#F#{@filenum}&quot;&gt;#{file}&lt;/a&gt;&lt;/h2&gt;&lt;table class='diff'&gt;
 &lt;colgroup&gt;
 &lt;col class=&quot;lineno&quot;/&gt;
 &lt;col class=&quot;lineno&quot;/&gt;
 &lt;col class=&quot;content&quot;/&gt;
 &lt;/colgroup&gt;
 EOF
-  @filenum += 1
   result
   end
   
@@ -93,7 +83,7 @@ EOF
     return left_ln, right_ln
   end
   
-  def get_diff(diff_file)
+  def get_single_file_diff(file_name, diff_file)
     @last_op = ' '
     @left = []
     @right = []
@@ -102,61 +92,118 @@ EOF
 
     diff = diff_file.split(&quot;\n&quot;)
     
-    index = diff.shift
-    file = index[7..-1]
-    diff.shift #equals
-    header1 = diff.shift
-    if header1 =~ /^---/
-      diff.shift
+    diff.shift #index
+    line = nil
+    while line !~ /^---/ &amp;&amp; !diff.empty?
+      line = diff.shift
+    end
+    header_old = line
+    if line =~ /^---/
+      diff.shift #+++
       
-      result &lt;&lt; &quot;&lt;ul class='diff'&gt;#{begin_file(file)}&quot;
+      result &lt;&lt; begin_file(file_name)
       range = diff.shift
       left_ln, right_ln = range_info(range)
       result &lt;&lt; range_row(range)
       
-      skip = 0
       diff.each do |line|
-        if skip &gt; 0
-          skip -= 1
+        op = line[0,1]
+        line = line[1..-1] || ''
+        if op == '\\'
+          line = op + line
+          op = ' '
+        end
+        
+        if ((@last_op != ' ' and op == ' ') or (@last_op == ' ' and op != ' '))
+          left_ln, right_ln = flush_changes(result, left_ln, right_ln)
+        end
+        
+        # truncate and escape
+        line = CGI.escapeHTML(line)
+
+        case op
+        when ' '
+          @left.push(line)
+          @right.push(line)
+        when '-' then @left.push(line)
+        when '+' then @right.push(line)
+        when '@' 
+          range = '@' + line
+          flush_changes(result, left_ln, right_ln)
+          left_ln, right_ln = range_info(range)
+          result &lt;&lt; range_row(range)
         else
-          op = line[0,1]
-          line = line[1..-1]
-          
-          if ((@last_op != ' ' and op == ' ') or (@last_op == ' ' and op != ' '))
-            left_ln, right_ln = flush_changes(result, left_ln, right_ln)
-          end
-          
-          # truncate and escape
-          line = CGI.escapeHTML(line)
-
-          case op
-          when ' '
-            @left.push(line)
-            @right.push(line)
-          when '-' then @left.push(line)
-          when '+' then @right.push(line)
-          when '@' 
-            range = '@' + line
-            flush_changes(result, left_ln, right_ln)
-            left_ln, right_ln = range_info(range)
-            result &lt;&lt; range_row(range)
-          when 'I'
-            file = line[6..-1]
-            flush_changes(result, left_ln, right_ln)
-            result &lt;&lt; &quot;&lt;/table&gt;&lt;/li&gt;#{begin_file(file)}&quot;
-            skip = 3
-          end
-          @last_op = op
+          flush_changes(result, left_ln, right_ln)
+          result &lt;&lt; &quot;&lt;/table&gt;&lt;/li&gt;&quot;
+          break
         end
+        @last_op = op
       end
 
       flush_changes(result, left_ln, right_ln)
-      result &lt;&lt; &quot;&lt;/table&gt;&lt;/li&gt;&lt;/ul&gt;&quot;      
+      result &lt;&lt; &quot;&lt;/table&gt;&lt;/li&gt;&quot;      
     else
-      result = &quot;&lt;div class='error'&gt;#{header1}&lt;/div&gt;&quot;
+      #&quot;&lt;div class='error'&gt;#{header_old}&lt;/div&gt;&quot;
+      result =%Q{&lt;li&gt;&lt;h2&gt;&lt;a name=&quot;F#{@filenum}&quot; href=&quot;#F#{@filenum}&quot;&gt;#{file_name}&lt;/a&gt;&lt;/h2&gt;#{header_old}&lt;/li&gt;}
     end
 
     result
   end
 
+  def file_header_pattern
+    raise &quot;Method to be implemented in VCS-specific class&quot;
+  end
+  
+  def get_diffs(composite_diff)
+    pattern = file_header_pattern
+    files = composite_diff.split(pattern)
+    headers = composite_diff.scan(pattern) #huh can't find a way to get both at once
+    files.shift if files[0] == '' #first one is junk usually
+    result = []
+    i = 0
+    files.each do |file|
+      result &lt;&lt; {:filename =&gt; &quot;#{file_prefix}#{get_filename(headers[i])}&quot;, :file =&gt; file}
+      i += 1
+    end
+    result
+  end
+
+  def diffs_to_html(diffs)
+    result = '&lt;ul class=&quot;diff&quot;&gt;'
+    @filenum = 0
+    diffs.each do |file_map|
+      result &lt;&lt; get_single_file_diff(file_map[:filename], file_map[:file])
+      @filenum += 1
+    end
+    result &lt;&lt; '&lt;/ul&gt;'
+    result    
+  end
+  
+  def composite_to_html(composite_diff)
+    diffs_to_html get_diffs(composite_diff)
+  end
+end
+
+class GitDiffToHtml &lt; DiffToHtml
+  def file_header_pattern
+    /^diff --git.+/
+  end
+
+  def get_filename(file_diff)
+    match = (file_diff =~ / b\/(.+)/)
+    raise &quot;not matched!&quot; if !match
+    $1
+  end  
+end
+
+class SvnDiffToHtml &lt; DiffToHtml
+  def file_header_pattern
+    /^Index: .+/
+  end
+
+  def get_filename(header)
+    match = (header =~ /^Index: (.+)/) #if we use this pattern file_header_pattern files split doesn't work
+    raise &quot;header '#{header}' not matched!&quot; if !match
+    $1
+  end  
 end</diff>
      <filename>lib/diff_to_html.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5aa681feb8eb31307aa1d35ffb60a9796cc0afd7</id>
    </parent>
  </parents>
  <author>
    <name>Artem Vasiliev</name>
    <email>artem.vasiliev@texunatech.com</email>
  </author>
  <url>http://github.com/artemv/diff_to_html.rb/commit/29447ffd38671d59d88f423798111250cdf7378b</url>
  <id>29447ffd38671d59d88f423798111250cdf7378b</id>
  <committed-date>2008-11-25T09:03:57-08:00</committed-date>
  <authored-date>2008-11-25T09:03:57-08:00</authored-date>
  <message>Some changes towards Git support</message>
  <tree>9715dfbb1881b8ec3b5bed1fc787a94449f87d48</tree>
  <committer>
    <name>Artem Vasiliev</name>
    <email>artem.vasiliev@texunatech.com</email>
  </committer>
</commit>
