Convert this character based table into html one Take a following character table:

-------------------------------------------------------
|       |1233456 | abc    | xyz    |        |         |
|-------|--------|--------|--------|--------|---------|
|       |abcdefgh| 1234567|        | 12345  |         |
|   abc |xyzabcqw|        |        |        |         |
|       |zzzz    |        |        |        |         |
|-------|--------|--------|--------|--------|---------|


It can have a variable number of columns or rows. Column width and row height can vary. Cells can be empty or have text, but the row height is optimized to wrap the text. So, second row has three lines because second cell content in second row is three lines high.

Input is ASCII text as shown in example. Cells can not contain | or - characters. Cell content should be escaped, but no need to worry about rowspan and colspan, since the table structure is always simple (every row same number of columns and every column same number of rows).

Output should be well-formed xhtml. Html table should reflect the table structure, content and line breaks. So, resulting html based on the sample input above is the following:

&lt;table&gt;
&lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;1233456&lt;/td&gt;
    &lt;td&gt;abc&lt;/td&gt;
    &lt;td&gt;xyz&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;abc&lt;/td&gt;
    &lt;td&gt;abcdefgh&lt;br/&gt;xyzabcqw&lt;br/&gt;zzzz&lt;/td&gt;
    &lt;td&gt;1234567&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;12345&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;


Shortest code which takes this table and turns it into an xhtml table wins.
Ruby: 233 characters
BEGIN{puts&quot;&lt;table&gt;&quot;;f=[]};if/^[-|]+$/ then if f!=[] then puts&quot;&lt;tr&gt;\n#{f[1..-2].map{|i|&quot;    &lt;td&gt;#{i.join&quot;&lt;br/&gt;&quot;}&lt;/td&gt;&quot;}*$/}\n&lt;/tr&gt;\n&quot;;f=[]end else$F.each_index{|i|f[i]||=[];f[i]&lt;&lt;CGI.escapeHTML($F[i])if$F[i]&gt;&quot;&quot;}end;END{puts&quot;&lt;/table&gt;&quot;}

Sample run:
bash-4.2$ ruby -naF' *\| *' -r cgi -e 'BEGIN{puts&quot;&lt;table&gt;&quot;;f=[]};if/^[-|]+$/ then if f!=[] then puts&quot;&lt;tr&gt;\n#{f[1..-2].map{|i|&quot;    &lt;td&gt;#{i.join&quot;&lt;br/&gt;&quot;}&lt;/td&gt;&quot;}*$/}\n&lt;/tr&gt;\n&quot;;f=[]end else$F.each_index{|i|f[i]||=[];f[i]&lt;&lt;CGI.escapeHTML($F[i])if$F[i]&gt;&quot;&quot;}end;END{puts&quot;&lt;/table&gt;&quot;}' table.txt
&lt;table&gt;
&lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;1233456&lt;/td&gt;
    &lt;td&gt;abc&lt;/td&gt;
    &lt;td&gt;xyz&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;abc&lt;/td&gt;
    &lt;td&gt;abcdefgh&lt;br/&gt;xyzabcqw&lt;br/&gt;zzzz&lt;/td&gt;
    &lt;td&gt;1234567&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;12345&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

(Out of contest CW, due to the shameless amount of used command line options.)