\n"; # is it a regex? $re = @$opt['re']; # $sep will either be a string (same for all) or an array of strings # (each column can be different) if (isset($opt['sep1'])) for ($i=1; isset($opt["sep${i}"]); $i++) $sep[$i-1] = $opt["sep${i}"]; elseif (isset($opt['sep'])) $sep = $opt['sep']; elseif (isset($opt['fmt'])) { // align-sep-align-sep-align $align = substr($opt['fmt'], 0, 1); for ($i=1; $i1, 'sep'=>1, 'align'=>1, 'fmt'=>1, 're'=>1, 'options'=>1, 'align'=>1, 'keepquotes'=>1, 'input'=>1, 'output'=>1, 'keeporiginal'=>1); for ($i=1; $i<25; $i++) $ValidOpts['sep'.$i] = 1; $newopt = array_diff_key($opt, $ValidOpts); if ($newopt) foreach ($newopt as $k=>$v) $opt['options'] .= ($opt['options']?" ":"") . "$k=$v"; ## ## Read from simple table ## if ($opt['input'] == 'simple') { if (preg_match("/^\s*\|\|\s*([^\|]*)$/", $lines[0], $m)) { array_shift($lines); $opt['options'] = ($opt['options']?$opt['options'].' ':'').$m[1]; } #echo "lines=
".print_r($lines,true)."

\n"; foreach ($lines as $k => &$line) { $line = preg_replace("/^\s*\|\|(.*?)(?:\|\|)?\s*$/s", "$1", $line); $cells[$k] = explode("||", $line); # Now check alignment and store override in an array... $lastcol=0; for ($i = 0; $i < sizeof($cells[$k]); $i++) { if ($x = t2tOptions($cells[$k][$i])) $options[$k][$col] = $x; if (!$cells[$k][$i] || preg_match("/^_{2,}$/", $cells[$k][$i])) { if ($colspan[$k][$lastcol]) $colspan[$k][$lastcol]++; else $colspan[$k][$lastcol] = 2; $cells[$k][$i] = ''; continue; } if (preg_match("/(\+{2,})(\s*)$/", $cells[$k][$i], $m)) { # Get rid of the +++ $cells[$k][$i] = preg_replace("/\+{2,}(\s*)$/", '$1', $cells[$k][$i]); $rowspan[$k][$i] = strlen($m[1]); } if (preg_match("/^\^{2,}$/", $cells[$k][$i])) { $cells[$k][$i] = ''; continue; } if (substr($cells[$k][$i], -1, 1) == ' ') { if (substr($cells[$k][$i], 0, 1) == ' ') $a = 'c'; else $a = 'l'; } elseif (substr($cells[$k][$i], 0, 1) == ' ') $a = 'r'; else $a = 'l'; if ($a != $align[$i]) { #echo "Overriding $k-$i: :".str_replace(" ", "X", $cells[$k][$i]).": $a
\n"; $align_override[$k][$i] = $a; } $lastcol = $i; } if ($i > $colcnt) $colcnt = $i; } $colcnt--; // some weird offset I've got going } else { ## ## Read from (:text2tbl ...:) "markup" ## if ($opt['quotes']) { $rpat = "/$KeepToken(\\d+P)$KeepToken/e"; $rrep = '$KPV[\'$1\']'; } if (!is_array($sep)) $s = $sep; foreach ($lines as $k => &$line) { # 9/23/2013 - no longer suppressing blank lines - may want an option at some point... #if (!$line) continue; if ($opt['quotes']) $line = preg_replace('/"([^"]*)"/e', "Keep(PSS('$1'), 'P')", $line); for ($col=0; $col<=$colcnt; $col++) { if (is_array($sep)) $s = $sep[$col]; if ($col == $colcnt) { if ($x = t2tOptions($line)) $options[$k][$col] = $x; $cells[$k][$col] = $line; } elseif (preg_match("/^((.*?)".$s.")/", $line, $m)) { #echo "DEBUG: col=$col, line=$line, m=
".print_r($m,true)."

\n"; if ($x = t2tOptions($m[2])) $options[$k][$col] = $x; $line = substr($line, strlen($m[1])); $cells[$k][$col] = $m[2]; } # Note: we can't give this message because a rowspan could # result in a column "missing" which is totally valid #else echo "DEBUG: OOPS! No match... sep=$s, line=$line
\n"; } } } #echo "DEBUG: cnt=$colcnt, cells=
".print_r($cells,true)."

\n"; #echo "align_override=
".print_r($align_override,true)."

\n"; $lines = array(); if ($opt['output'] == 'advanced') { $aligntbl=array('l'=>' align=left', 'r'=>' align=right', 'c'=>' align=center'); if ($t2tEnableSuppressDefaultAlign) $aligntbl['l'] = ''; $lines[] = "(:table $opt[options]:)"; $newtbl=''; for ($j=0; $j\n"; $line = "(:cell" . ($col==0?'nr':'') . $aligntbl[$a]; if (substr($cells[$j][$col], 0, 1) == '!') { $cells[$j][$col] = substr($cells[$j][$col], 1); $line .= " style='text-align:center; font-weight:bold;'"; } if ($options[$j][$col]) $line .= ' '.$options[$j][$col]; if ($opt['attr'.($col+1)]) $line .= ' '.$opt['attr'.($col+1)]; if ($opt['attr']) $line .= ' '.$opt['attr']; if ($colspan[$j][$col]) $line .= " colspan=".$colspan[$j][$col]; if ($rowspan[$j][$col]) $line .= " rowspan=".$rowspan[$j][$col]; $line .= ":)"; $cell = trim($cells[$j][$col]); if ($opt['quotes']) { if ($opt['keepquotes']) $cell = preg_replace($rpat, '\'"\'.'.$rrep.'.\'"\'', $cell); else $cell = preg_replace($rpat, $rrep, $cell); } $lines[] = $line.$cell; } } $lines[] = "(:tableend:)"; } else { $newtbl = "|| $opt[options]\n"; for ($j=0; $j\n"; $line = "||${right}".$cells[$j][$col]; if (substr(ltrim($cells[$j][$col]), 0, 1) == '!') $line = "||!${right}".substr($cells[$j][$col], 1); else $line = "||${right}".$cells[$j][$col]; } elseif ($col == $colcnt+1) { #echo "2: ".substr($cells[$j][$col], 0, 1). "
\n"; $line = "${line}${left}||"; } else { #echo "3: ".substr($cells[$j][$col], 0, 1). "
\n"; if (substr(ltrim($cells[$j][$col]), 0, 1) == '!') $line = "${line}${left}||!${right}". substr($cells[$j][$col], 1); else $line = "${line}${left}||${right}".$cells[$j][$col]; } } if ($opt['quotes']) { if ($opt['keepquotes']) $line = preg_replace($rpat, '\'"\'.'.$rrep.'.\'"\'', $line); else $line = preg_replace($rpat, $rrep, $line); } $lines[] = $line; } } if ($opt['keeporiginal']) { $newtbl = $text2tbl_begin ."\n". $tabledef . "(:end-of-original-data (THE TABLE BELOW WILL BE OVER-WRITTEN EVERY TIME THIS PAGE IS SAVED!) Specify keeporiginal=0 if you want to get rid of the text above.:)\n". $newtbl . implode("\n",$lines) ."\n". $text2tbl_end; } else $newtbl .= implode("\n",$lines); return($newtbl); } function t2tOptions(&$string) { if (preg_match("/^\s*\(:t2t\s([^:]*):\)(.*)$/", $string, $m)) { $opt = $m[1]; $string = $m[2]; // as a side effect, strip this (:t2t ...:) markup return($opt); } else return(''); } # If keep=1 was specified then the original data is maintained in the source, # but it must not be displayed. This markup makes the original data (and the # text2tbl markup) invisible. Markup('t2t-comment', '<{$var}', "/\(:text2ta?ble?[^\n]*:\).*?\(:end-of-original-data[^:]*:\)\n(.*?)\n\(:text2ta?ble?end:\)/s", PSS('$1')); # This will implement a "real" markup which will convert any of the usual # types of structured text (as implemented in Text2Tbl() above) but will not # alter the source Markup('flextable', '