csv.pl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 3 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, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('csv.pl', 'Comments on Long Table Markup Extension');
  18. our ($bol, @MyRules);
  19. push(@MyRules, \&CsvRule);
  20. my $RowCount;
  21. sub CsvRule {
  22. # tables using <csv> -- the first row of a table
  23. if ($bol && m/\G&lt;csv&gt;\n/cg) {
  24. $RowCount = 1;
  25. return OpenHtmlEnvironment('table',1,'user csv')
  26. . AddHtmlEnvironment('tr', 'class="odd first"')
  27. . AddHtmlEnvironment('td');
  28. }
  29. # end of the row and beginning of the next row
  30. elsif (InElement('td') && m/\G[ \t]*\n([ \t]*)/cg) {
  31. my $type = ++$RowCount % 2 ? 'odd' : 'even';
  32. return qq{</td></tr><tr class="$type"><td>};
  33. }
  34. # an ordinary table cell
  35. elsif (InElement('td') && m/\G[ \t]*,[ \t]*/cg) {
  36. return "</td><td>";
  37. }
  38. # an empty line will end the table automatically; no closing tag is required
  39. return;
  40. }