方針
- 字下げ書式では、行頭の空白は無視されるため、従来の空白整形済みテキストに代わる書式が必要。
- 書式には目に見える文字を当てるべし。
- 先頭が「^」で始まる「H整形/Hat整形」を導入。
- 正規表現で行頭を示す「^」から連想:「^」は真の行頭、以降は一字一句そのまま出力。
- Wikiで引用を表す矢印形「>」や「<」からの連想:実際、何かの引用である場合が多い。
- 以降では便宜上、空白で始まる整形済みテキストの書式を「S整形/Space整形」で区別。
仕様
改造
- lib/convert_html.php で、S整形のクラス class Pre をコピー。場所は任意だが、流れ的にS整形の直後で、
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
| | ! // '^ 'Hat-beginning sentence
! // '^ 'Hat-beginning sentence
! // '^ 'Hat-beginning sentence
! class HPre extends Element // for Indent extension
{
! function HPre(& $root, $text)
{
parent::Element();
$this->elements[] = htmlspecialchars(substr($text, 1));
}
function canContain(& $obj)
{
! return is_a($obj, 'HPre');
}
function & insert(& $obj)
{
$this->elements[] = $obj->elements[0];
return $this;
}
function toString()
{
return $this->wrap(join("\n", $this->elements), 'pre');
}
}
|
- 「!」で始まる行は class Pre との差分。
- 'HPre' はH整形の識別キーであり、クラス名との一致が必要。
- 同ファイルの class Body の function parse の while (! empty($lines)) 中にて、Pre に関する分岐をコピーし、
1
2
3
4
5
6
7
8
9
10
11
| | // Pre
- if ($head == ' ' || $head == "\t") {
+ if (!$indent_format && ($head == ' ' || $head == "\t")) {
$this->last = & $this->last->add(new Pre($this, $line));
continue;
}
+ // HPre
+ if ($head == '^') {
+ $this->last = & $this->last->add(new HPre($this, $line));
+ continue;
+ }
|
- !$indent_format && は字下げ書式でS整形を無効化する条件。
- if ($head == '^') はH整形への分岐。
コメント
コメントはありません。 コメント/PukiWiki改造/H整形書式?