Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML table to “graphical text” for code comments

Is there a tool (ideally command-line-based) that can help in converting the source to HTML tables into “graphical text” (think perhaps ASCII art for HTML tables) for use in code comments, as show below?

For example, given the following HTML table source

<TABLE BORDER=1>
  <CAPTION>A test table with merged cells</CAPTION>
  <TR><TH ROWSPAN=2><TH COLSPAN=2>Average
  <TH ROWSPAN=2>other<BR>category<TH>Misc
  <TR><TH>height<TH>weight
  <TR><TH ALIGN=LEFT>males<TD>1.9<TD>0.003
  <TR><TH ALIGN=LEFT ROWSPAN=2>females<TD>1.7<TD>0.002
</TABLE>

the tool would output something like the following to be embedded into code comments (like /*…*/):

/*
          A test table with merged cells
+----------+-------------------+----------+--------+ 
|          |      Average      |  other   |  Misc  |
|          +---------+---------+ category +--------|
|          |  height |  weight |          |        |
|----------+---------+---------+----------+--------|
| males    |   1.9   |  0.003  |          |        |
|----------+---------+---------+----------+--------|
| females  |   1.7   |  0.002  |          |        |
+----------+---------+---------+----------+--------+
*/

Background: A piece of code that reads values from HTML tables can be annotated with comments depicting text-based graphical representations of complex HTML table layouts. Someone maintaining the code later can then find it easier to understand, for example, how a piece of code is slicing and dicing an HTML table or plucking values at certain cell positions.

like image 375
Atif Aziz Avatar asked May 17 '10 11:05

Atif Aziz


2 Answers

  elinks -dump 1 

http://elinks.or.cz/documentation/manpages/elinks.1.html

like image 95
SF. Avatar answered Oct 13 '22 20:10

SF.


HTML::TreeBuilder plus Text::ASCIITable looks like they would need only a little glue to do the job.

like image 29
Quentin Avatar answered Oct 13 '22 20:10

Quentin