PukiWiki/1.4/ちょっと便利に

行頭<pre>~行頭</pre>間を整形済みとする

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

1.4.7-1.5.3

$ 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

1.4.4

少し場所を考えれば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

1.4.4_php5, 1.4.6

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));
+			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

1.4.6以降では PukiWiki/1.4/ちょっと便利に/複数行のプラグイン引数を可能に の機能が組み込まれている(デフォルトでは無効)ので、 official:自作プラグイン/codehighlight.inc.php 梱包の pre.inc.php を使用すればよいだろう。

#pre{{
hoge
}}
#pre(soft){{
&size(20){hoge};
}}

添付ファイル: fileblock_pre.diff 3308件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2020-05-11 (月) 01:07:40
Site admin: PukiWiki Development Team

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

SourceForge