#author("2020-05-11T01:14:55+09:00","default:webadmin","webadmin") #author("2020-05-11T10:54:26+09:00","","") **[[質問箱/5373]] [#fda0bb52] |RIGHT:70|LEFT:410|c |~カテゴリ|動作環境| |~サマリ|行頭<pre>~行頭</pre>間を整形済みとする| |~バージョン|1.5.3| |~投稿者|[[p]]| |~状態|質問| |~投稿日|&new{2020-05-06 (水) 14:45:58};| ***質問 [#cf26aaac] 1.5.0で [[dev:PukiWiki/1.4/ちょっと便利に/整形済みブロック]] の「行頭<pre>~行頭</pre>間を整形済みとする」を利用していました~ 1.5.3を新規に入れていつも通りカスタマイズしたのですが、<pre>の次の1行しか表示されませんでした~ (2行目以降は空白になります) 仮対応として以下の行を変更 - $this->last = &$this->last->add(new $class($this, $line)); + $this->last = &$this->last->add(new Pre($this, $line)); テキスト表示はできるようにしました。 しかし、このままでは<pre>中のhttp*がリンクにならないので修正方法分かる方いましたらお願いします。 ***回答 [#c668993d] - 少し改変してやってみましたが『1.5.3を新規に入れていつも通りカスタマイズしたのですが、<pre>の次の1行しか表示されませんでした (2行目以降は空白になります)』こうはなりませんでした。全行囲まれます。ただ、pre中の表示が変ですね。改行が増えるしURLはリンクになりません -- [[umorigu]] &new{2020-05-10 (日) 18:01:57}; $ git diff diff --git a/lib/convert_html.php b/lib/convert_html.php index 0f4c42b..887622d 100644 --- a/lib/convert_html.php +++ b/lib/convert_html.php @@ -808,6 +808,20 @@ class Pre extends Element } } +class Pre_inline extends Pre +{ + function Pre_inline(&$root, $text) + { + $this->__construct($root, $text); + } + + function __construct(&$root, $text) + { + parent::__construct($root, $text); + $this->elements[] = make_link($text); + } +} + // Block plugin: #something (started with '#') class Div extends Element { @@ -898,6 +912,8 @@ class Body extends Element $matches = array(); while (! empty($lines)) { + $this->tagblock($lines, '<pre>', '</pre>', 'Pre'); + $this->tagblock($lines, '<pre2>', '</pre2>', 'Pre_inline'); $line = array_shift($lines); // Escape comments @@ -1032,6 +1048,21 @@ class Body extends Element '</div>' . "\n"; return $contents; } + + 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)); + } + } } class Contents_UList extends ListContainer - 確認有難うございます。最初の1行しか表示されないのは「1.4.4_php5, 1.4.6」の「Pre_inline」の通りにいしていたからですね。umoriguさんのようにすれば全行表示できました。リンクにならないのはmake_linkが上手くいっていないようですが、まだデバッグできずにいます。 -- [[p]] &new{2020-05-10 (日) 23:18:41}; - 失礼しました。ご提示のコードだと1行目が2回表示されますね。 -- [[p]] &new{2020-05-10 (日) 23:21:00}; - 直りました。 ( pre と pre2 があるんですね ) -- [[umorigu]] &new{2020-05-11 (月) 01:01:30}; -- 修正箇所: (1)改行削除の \\r\\n がなぜか ?r?r に代わっていた。 (2) Pre_inline::_construct() で $this->elements は parent::__construct() で設定済みなので elements[] で末尾追加するのではなく、 elements の上書きが必要。 (3) PHP4 対応 (Pre_inline()) 削除 -- [[umorigu]] &new{2020-05-11 (月) 01:13:21}; $ git diff diff --git a/lib/convert_html.php b/lib/convert_html.php index 0f4c42b..18619b0 100644 --- a/lib/convert_html.php +++ b/lib/convert_html.php @@ -808,6 +808,15 @@ class Pre extends Element } } +class Pre_inline extends Pre +{ + function __construct(&$root, $text) + { + parent::__construct($root, $text); + $this->elements = array(make_link($text)); + } +} + // Block plugin: #something (started with '#') class Div extends Element { @@ -898,6 +907,8 @@ class Body extends Element $matches = array(); while (! empty($lines)) { + $this->tagblock($lines, '<pre>', '</pre>', 'Pre'); + $this->tagblock($lines, '<pre2>', '</pre2>', 'Pre_inline'); $line = array_shift($lines); // Escape comments @@ -1032,6 +1043,21 @@ class Body extends Element '</div>' . "\n"; return $contents; } + + 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)); + } + } } class Contents_UList extends ListContainer - [[dev:PukiWiki/1.4/ちょっと便利に/整形済みブロック]]も更新しておきました -- [[umorigu]] &new{2020-05-11 (月) 01:14:05}; - umoriguさん、そういうことでしたか!こちらでも修正されました。有難うございます。 -- [[p]] &new{2020-05-11 (月) 10:54:26}; #comment