#author("2020-05-11T01:07:40+09:00","default:webadmin","webadmin") [[PukiWiki/1.4/ちょっと便利に]] * 行頭<pre>~行頭</pre>間を整形済みとする [#vad944fd] <pre> 整形済み A quick red fox jumped over the lazy brown dogs. </pre> ** 1.4.7-1.5.3 [#l5ce0fc4] $ 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 ** 1.4.3 [#y084a3f1] #ref(block_pre.diff); -[[pukiwiki-1.4.3用>official:自作プラグイン/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タグで囲うがインラインプラグイン、リンク展開をする $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)); + $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) { に変更すればよい。 ** 1.4.6 [#l81e3a5e] 1.4.6以降では [[PukiWiki/1.4/ちょっと便利に/複数行のプラグイン引数を可能に]] の機能が組み込まれている(デフォルトでは無効)ので、 [[official:自作プラグイン/codehighlight.inc.php]] 梱包の [[pre.inc.php>Code.dev:Pre]] を使用すればよいだろう。 #pre{{ hoge }} #pre(soft){{ &size(20){hoge}; }}