title: Lisp script to parse csv and generate HTML table?
body: <p>I'm trying to write a little Emacs Lisp script that reads a csv file from standard input, turns all the rows into a table then prints it to standard out (Unix).  I wrote a basic version that takes a csv string and outputs the table to a buffer.  However, I would like to turn this into a Unix utility script.</p>
  
  <pre>
  <b>#!/usr/bin/emacs --script</b>
  
  (defun gen-row (lst)
    (dolist (elm lst)
      (insert "&lt;tr>")
      (insert (concat "&lt;td>" elm "&lt;/td>"))
      (insert "&lt;/tr>")
      )
  )
  (defun parse-csv-line (txt)
    (setq lst (progn
            (insert "\n&lt;table>\n")
            (setq str txt)
            (gen-row (split-string str ","))
            (insert "\n&lt;/table>\n")
            ))
    )
  
  (parse-csv-line "this,is,a test")
  </pre>
  
  <p>The output to the current buffer when run from within Emacs:</p>
  
  <pre>
  &lt;table>
  &lt;tr>&lt;td>this&lt;/td>&lt;/tr>&lt;tr>&lt;td>is&lt;/td>&lt;/tr>&lt;tr>&lt;td>a test&lt;/td>&lt;/tr>
  &lt;/table>
  </pre>
  
  <p>Usage of the script:</p>
  
  <pre>
  ./csv2html &lt; foo.csv > bar.html; # emacs --script instead of perl -ane '...' 
  </pre>