|
方針 - 便宜上、行頭が「|」の表を「P表組/Pipe表組」、行頭が「,」の表を「C表組/Comma表組」で区別する。
- P表組では、縦方向の関連性が強いので、空白による整列はコードの可読性向上に必要。
- P表組では、行方向のセル連結は右方向(>)でも良いが、左方向の連結も必要。
- コードは左から右、上から下に向かって読むもの。列方向と同様、結合記号より先にセル内容を記述すべき。
- 「~」は列方向のセル連結と、ヘッダ(th)の2つの意味がある上、空白による整列を許すと構文が衝突する。
- 「>」からの連想で、左向き連結に「<」を、上向き連結に「^」を導入。
- 「*」などからの連想で、ヘッダに「^」を導入。
仕様 - セル内の先頭と末尾の空白を無視。
- 「>」のみのセルは右のセルに連結。
- 「^」のみのセルは上のセルに連結。
- 「<」のみのセルは左のセルに連結。(互換仕様)
- 「~」のみのセルは上のセルに連結。(互換仕様)
- 「*」で始まるセルはヘッダ(th)。
- 「~」で始まる非空白セルはヘッダ(th)。(互換仕様)
課題 - レイアウト上、 |>|xxxx|<| のように、連結セルの内容を真ん中に書く「左右挟み連結」ができると便利かも。
- 左からのスキャンと右からのスキャンを纏められると精神的に宜しいかも。
改造 - convert_html.php の class TableCell にて、
1
2
3
4
5
6
7
| | class TableCell extends Element
{
var $tag = 'td'; // {td|th}
+ var $colleft = 0; // ==0: colspan to right by '>'; ==1: colspan to left by '<';
var $colspan = 1;
var $rowspan = 1;
var $style; // is array('width'=>, 'align'=>...);
|
- $colleftは行結合方向を表す変数。
- $colleft = 0 ⇔ 左に連結。
- $colleft = 1 ⇔ 右に連結。
- 同クラスのfunction TableCell にて、
1
2
3
4
5
| | function TableCell($text, $is_template = FALSE)
{
parent::Element();
$this->style = $matches = array();
+ $text = trim($text);
|
- 同関数 セル結合の分岐にて、
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| | if ($text == '>') {
+ $this->colleft = 0;
$this->colspan = 0;
+ } else if ($text == '<') {
+ $this->colleft = 1;
+ $this->colspan = 0;
- } else if ($text == '~') {
+ } else if ($text == '^' || $text == '~') {
$this->rowspan = 0;
- } else if (substr($text, 0, 1) == '~') {
+ } else if (substr($text, 0, 1) == '*' || substr($text, 0, 1) == '~') {
$this->tag = 'th';
$text = substr($text, 1);
}
|
- $this->colleft の追加は連結向きの指定。
- if ($text == '<') は左向き連結。
- $text == '^' || は上向き連結。
- substr($text, 0, 1) == '*' || はヘッダ。
- 同関数 セル結合ループにて、右向き連結のオリジナルに対して変更し、さらに左向き連結用にコピー、
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| | ! // Set colspan and style, from right to left.
+ $stylerow = NULL;
+ foreach (array_keys($this->elements) as $nrow) {
+ $row = & $this->elements[$nrow];
+ if ($this->types[$nrow] == 'c')
+ $stylerow = & $row;
+ $colspan = 1;
! foreach (array_reverse(array_keys($row)) as $ncol) {
! if ($row[$ncol]->colspan == 0 && $row[$ncol]->colleft == 1) {
+ ++$colspan;
+ continue;
+ }
+ if ($row[$ncol]->colspan > 0 && $row[$ncol]->$colspan < $colspan) {
+ $row[$ncol]->colspan = $colspan;
+ }
+ if ($stylerow !== NULL) {
+ $row[$ncol]->setStyle($stylerow[$ncol]->style);
+ // Inherits column style
+ while (--$colspan)
! $row[$ncol + $colspan]->setStyle($stylerow[$ncol]->style);
+ }
+ $colspan = 1;
+ }
+ }
- // Set colspan and style
+ // Set colspan and style, from left to right.
$stylerow = NULL;
foreach (array_keys($this->elements) as $nrow) {
$row = & $this->elements[$nrow];
if ($this->types[$nrow] == 'c')
$stylerow = & $row;
$colspan = 1;
foreach (array_keys($row) as $ncol) {
- if ($row[$ncol]->colspan == 0) {
+ if ($row[$ncol]->colspan == 0 && $row[$ncol]->colleft == 0) {
++$colspan;
continue;
}
+ if ($row[$ncol]->colspan > 0 && $row[$ncol]->colspan < $colspan) {
$row[$ncol]->colspan = $colspan;
+ }
if ($stylerow !== NULL) {
$row[$ncol]->setStyle($stylerow[$ncol]->style);
// Inherits column style
while (--$colspan)
$row[$ncol - $colspan]->setStyle($stylerow[$ncol]->style);
}
$colspan = 1;
}
}
|
- 「!」で始まる行は、コピーからの差分。
- 内側ループ foreach (array_reverse(array_keys($row)) as $ncol) の array_reverse でスキャン向きを反転する仕組み。
- $row[$ncol + $colspan]->setStyle($stylerow[$ncol]->style); の符号 + は連結方向の影響。
|