查看 継承
文件信息- 类别(标签)
- 根
- 文件名
- subclass
- 最后更新
- 2008-10-16 11:04
- 类型
- Plain Text
- 编辑器
- ht
- 描述
- サブクラスを作る時のメモ
- 语言
- 日语
- 翻译
自分用の記法を作ろうとした時など、parent::text2html()の結果を使うと、サブクラス内のメソッドがうまく動かなくなります。
原因は、どの記法もhtmlエレメントも適用されていない行は段落に変換する処理にあります。
記法は、行頭の、文字列に着目するので、行頭が<p>煮変換された結果に、新しい記法を適用しようとすると、一行目が変換されません。二行目以降は、<br>で改行されるので、行頭に狙いの文字列が見つかり、変換されるという現象が発生します。
したがって、 class trans を継承するには、<p>エレメントを除去してから変換する必要があります。
如何に、サンプルをメモします。
<?php
include("text2html/scripts/trans.php");
class trans2 extends trans {
function add(){
$buffer = preg_replace("|<\/?p[^>]*>|u","",$this->text2html());
//$buffer = $this->text2html_list($buffer,"\n","blockquote",'_','p','','','quote');
$buffer = parent::text2html_list($buffer,"\n","blockquote",'_','p','','','quote');
return $buffer;
}
}
$document=<<<DOC
**test
_炎
_炎
qrcode>(test)
DOC;
$a = new trans2($document);
echo $a->add();
ht.2008/10/16
| |