[[PukiWiki/1.4/ちょっと便利に]]

* 行頭<pre>~行頭</pre>間を整形済みとする [#vad944fd]

 <pre>
 整形済み
 A quick red fox jumped over the lazy brown dogs.
 </pre>

#ref(block_pre.diff);

-[[pukiwiki-1.4.3用>org:自作プラグイン/pre.inc.php]]


** 1.4.4 [#va19fc65]
少し場所を考えれば1.4.4でも上記パッチは使えます。具体的にはlib/convert.html.phpの

 @@ -792,6 +800,8 @@
  		
  		while (count($lines))
  		{
 +			$this->tagblock($lines, '<pre>', '</pre>', 'Pre_inline');
 +			
  			$line = array_shift($lines);
  			
  			if (substr($line,0,2) == '//') //コメントは処理しない
~の代わりに、867行目あたりに以下を追加
 	function parse(& $lines)
 	{
 		$this->last = & $this;
 		$matches = array();
 
 	 	while (! empty($lines)) {
 +			$this->tagblock($lines, '<pre>', '</pre>', 'Pre_inline');
 			$line = array_shift($lines);

** 1.4.5 [#vfbb2591]
- 1.4.4と同様に、少し場所(行)を考えれば上記パッチは使える。

** 1.4.4_php5, 1.4.6 [#d9915645]
lib/convert_html.php 中に Pre_inline クラス、Body#tagblock 関数がなくなっているので付け足す必要がある

好きなところで良いが、Pre クラスの下あたりが理にかなっているだろう。
 +class Pre_inline extends Pre
 +{
 +	function Pre_inline(&$root,$text)
 +	{
 +		parent::Element();
 +		$this->elements[] = make_link($text);
 +	}
 +}

 class Body extends Element
 {
 .....
 	function parse(& $lines)
 	{
 		$this->last = & $this;
 		$matches = array();
 
 		while (! empty($lines)) {
 +		    $this->tagblock($lines, '<pre>', '</pre>', 'Pre'); //通常整形済みテキスト
 +		    $this->tagblock($lines, '<pre2>', '</pre2>', 'Pre_inline'); //preタグで囲うがpukiwiki文法を展開する
 		    $line = array_shift($lines);
 .....
 +
 +	function tagblock(&$lines, $start, $end, $class)
 +	{
 +		if (rtrim($lines[0]) != $start) {
 +			return;
 +		}
 +		array_shift($lines);
 +		while (count($lines)) {
 +			$line = preg_replace('/[?r?n]*$/', '',  array_shift($lines));
 +			if ($line == $end) {
 +				return;
 +			}
 +			$this->last = &$this->last->add(new $class($this, $line));
 +		}
 +	}
 }

なお、PRE タグの大文字小文字を区別しないなら、上記 tagblock 中の
 if (rtrim($lines[0]) != $start) {
行を
 if (strcasecmp(rtrim($lines[0]), $start) != 0) {
に、
 if ($line == $end) {
行を
 if (strcasecmp($line, $end) == 0) {
に変更すればよい。

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 8.2.12. HTML convert time: 1.302 sec.

SourceForge