カテゴリ | 動作環境 |
---|---|
サマリ | 行頭<pre>~行頭</pre>間を整形済みとする |
バージョン | 1.5.3 |
投稿者 | p |
状態 | 質問 |
投稿日 | 2020-05-06 (水) 14:45:58 |
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*がリンクにならないので修正方法分かる方いましたらお願いします。
$ 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
$ 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