IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 24, 2012, 11:08:11 AM (14 years ago)
Author:
eugene
Message:

add inline markdown and dirlist

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120905/dvodist/www-util/ipp.php

    r34543 r34551  
    3434}
    3535
     36// generate the menu based on the text file
    3637function menulines ($source, $root, $append, $project) {
    3738
     
    4344    if (count($line) < 2) continue;
    4445
     46    // allow load of other menu files
    4547    if (count($line) == 2) {
    4648      $value = trim($line[0]);
     
    5153      continue;
    5254    }
     55
     56    // blithly skip lines with invalid entries
    5357    if (count($line) != 5) continue;
    5458
     
    158162}
    159163
     164function parse_dirlist ($input) {
     165  echo "<table class=\"dirlist\">\n";
     166
     167  $inlist = explode ("\n", $input);
     168  $Ninlist = count($inlist);
     169  for ($i = 0; $i < $Ninlist; $i++) {
     170    $inline = trim ($inlist[$i], "@ \t");
     171    $line = explode (":", $inline);
     172    if (ereg ('^[:blank:]*#', $line[0])) continue;
     173    if (count($line) < 2) continue;
     174    if (count($line) != 4) continue;
     175
     176    $name  = trim($line[0]);
     177    $type  = trim($line[1]);
     178    $style = trim($line[2]);
     179    $info  = trim($line[3]);
     180
     181    switch ($type) {
     182    case 'plain':
     183      echo "<tr class=\"$style\"><td>$name</td><td>$info</td></tr>\n"; 
     184      break;
     185    case 'dir':
     186      echo "<tr class=\"$style\"><td><a class=\"$style\" href=\"$name\">$name</a></td><td>$info</td></tr>\n";
     187      break;
     188    default:
     189      echo "<tr class=\"$style\"><td><a class=\"$style\" href=\"$name\">$name</a></td><td>$info</td></tr>\n";
     190      break;
     191    }
     192  }
     193  echo "</table>\n";
     194}
     195
    160196function verbatim ($source) {
    161197  $file = fopen ($source, "r");
     
    180216}
    181217
     218// lines which start with @ are processed by 'dirlist', all others are processed by Markdown
    182219function do_markdown ($source) {
    183220  $file = fopen ($source, "r");
    184221
    185222  // loop over the lines in the file and generate lines in the menu
    186   $ascii = "";
     223  $to_markdwn = "";
     224  $to_dirlist = "";
    187225  while ($line = fgets ($file, 1024)) {
    188     $ascii .= $line;
    189   }
    190   fclose ($file);
    191   $my_html = Markdown($ascii);
    192   echo "$my_html";
     226    // echo "line: $line";
     227    if (!strncmp($line, "@", 1)) {
     228      if ($to_markdwn) {
     229        // echo "<b> start markdown</b><br>\n";
     230        $my_html = Markdown($to_markdwn);
     231        echo "$my_html";
     232        $to_markdwn = "";
     233      }
     234      $to_dirlist .= $line;
     235    } else {
     236      if ($to_dirlist) {
     237        // echo "<b> start dirlist</b><br>\n";
     238        parse_dirlist($to_dirlist);
     239        $to_dirlist = "";
     240      }
     241      $to_markdwn .= $line;
     242    }
     243  }
     244  // echo "end of lines<br>\n";
     245  // echo "to_markdwn: $to_markdwn\n";
     246  // echo "<br>\n";
     247  // echo "to_dirlist: $to_dirlist\n";
     248  // echo "<br>\n";
     249
     250  if ($to_markdwn) {
     251    $my_html = Markdown($to_markdwn);
     252    echo "$my_html";
     253    $to_markdwn = "";
     254  }
     255  if ($to_dirlist) {
     256    parse_dirlist($to_dirlist);
     257    $to_dirlist = "";
     258  }
     259  fclose ($file);
    193260}
    194261
Note: See TracChangeset for help on using the changeset viewer.