[pmwiki-users] Even Simpler Tables

Martin Fick fick at fgm.com
Mon Apr 18 12:14:58 CDT 2005


   I am investigating creating a very simple table markup
that allow the number of columns to vary easily. I am not
sure what a good syntax would be and I am not sure exactly
how to best implement it.  

Here is what I have currently:

  Authors can define (:columns <n> <includefile>:) which
will then include the text in wiki-file <includefile> and
put each line in a separate  table cell.  The number of
columns is defined by <n>.

Example:

  (:columns 2 file-with-10-lines:)

would render as:

  line1  line2
  line3  line4
  line5  line6
  line7  line8
  line9  line10

simply by changing 2 to 3 you can get:

  (:columns 3 file-with-10-lines:)

  line1  line2  line3
  line4  line5  line6
  line7  line8  line9
  line10


  This allows authors to define table contents without
having to know or care how many columns are in the table. 
It allow the number of columns to be changed without the
contents of the table being changed.  Obviously this is 
only valuable where table cells have data that is  not
column specific.  A good example of this is an index of
photo thumbnails.  Another good use would be  for pagelist
outputs (not with the current implementation).

  I chose the current implementation because it was the
easiest implementation, but although simple, in many cases
it is not the best markup  for authors.  I think it is a
good option, but  would like to offer other options.


Some future ideas:

1) Allow authors to define table contents
  in same file, maybe like this:


  (:table columns=3:)

   col1 
   col2
   col3

  (:tableend:)


  But I don't know how to create the markup for this (How
to you span lines with regexps?).  This would be  easier
for me to implement by imitating the advanced columns and
using (:cell) at the beginning of each line, but in this
case that seems like a lot of work for authors.


2) Instead oc a columns markup, make fmt=column:n a format
  for various directives.  i.e.  

  (:include fmt=column:3 file:)
  (:pagelist fmt=column:3 group=...:)
  (:table fmt=column:3 :)
  ...


3) Allow columns to accumulate vertically instead of
  horizontally.

i.e.

horizontal:

  cell1  cell2
  cell3  cell4
  cell5  cell6

vertical:
  
  cell1   cell4
  cell2   cell5
  cell3   cell6

  
  Anybody have any thoughts on this?

  -Martin


-----------------------------------------------------------  

Sample columns code:

<?php if (!defined('PmWiki')) exit();
  
function FmtCol($ncols, $cells) {
  $out[] = '<TABLE>';
  foreach($cells as $cell) {
    if ($c == 0) $out[]='<TR>';
    $c++;
    $out[]="<TD> $cell </TD>";
    if ($c == $ncols) { $c=0; $out[] = '</TR>'; }
  }
  if ($c>0 && $c < $ncols) {
    while($c < $ncols) { $c++; $out[] = '<TD></TD>'; }
    $out[] = '</TR>';
  }
  $out[] = '</TABLE>';
  return implode($out);
}
function FmtColI($current, $ncols, $pagename) {
  $page = IncludeText($current, "include $pagename");
  $cells = explode("\n", $page);
  return FmtCol($ncols, $cells);
}

Markup('columns','>if',"/\\(:columns\\s*([^\\s]*)\\s*([^\\s]*):\\)/e",
  "PRR().FmtColI(\$pagename, '$1', '$2')");

?>



More information about the pmwiki-users mailing list