csv.pl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2007 Alex Schroeder <alex@emacswiki.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('csv.pl', 'Comments on Long Table Markup Extension');
  21. our ($bol, @MyRules);
  22. push(@MyRules, \&CsvRule);
  23. my $RowCount;
  24. sub CsvRule {
  25. # tables using <csv> -- the first row of a table
  26. if ($bol && m/\G&lt;csv&gt;\n/cg) {
  27. $RowCount = 1;
  28. return OpenHtmlEnvironment('table',1,'user csv')
  29. . AddHtmlEnvironment('tr', 'class="odd first"')
  30. . AddHtmlEnvironment('td');
  31. }
  32. # end of the row and beginning of the next row
  33. elsif (InElement('td') && m/\G[ \t]*\n([ \t]*)/cg) {
  34. my $type = ++$RowCount % 2 ? 'odd' : 'even';
  35. return qq{</td></tr><tr class="$type"><td>};
  36. }
  37. # an ordinary table cell
  38. elsif (InElement('td') && m/\G[ \t]*,[ \t]*/cg) {
  39. return "</td><td>";
  40. }
  41. # an empty line will end the table automatically; no closing tag is required
  42. return;
  43. }