TITLE:字下げ書式の導入
%indent
%indent
#contents
//-- convert_html L977 L981 L986
////////////////////////////////////////////////////////////////
* 方針 [#fbf6bd7e]
- Wikiは行指向のため、コードの見通しが悪くなりがち。
特にリストでの改行とか、複数行プラグインとか。
- 字下げを導入でコード可読性を改善可能。
////////////////////////////////////////////////////////////////
* 仕様 [#m9bc6a64]
- 字下げ書式モードでは、行頭の空白は無視。
-- ただし、複数行プラグインの引数に対しては、プラグインの先頭行の字下げ分のみを無視。~
例:
^ #plugin(){{
^ arg
^ arg
^ }}
は、
^#plugin(){{
^ arg
^ arg
^}}
と等価。
- 疑似プラグイン ##&#;indent## で字下げ書式モードに切り替え。
- 疑似プラグイン ##&#;noindent## で天突き書式モードに切り替え。
- デフォルトは天突き書式。
- 字下げ書式では、行頭が空白の整形済みテキストは無効。
////////////////////////////////////////////////////////////////
* 改造 [#cfaf32ae]
- ##pukiwiki.ini.php## の適当な場所にて、
#code(diff){{
+ $indent_format = 0;
}}
-- ##$indent_format## は天突きと字下げを表すフラグ。
--- ##$indent_format = 0## ⇔ 天突き書式。(デフォルト)
--- ##$indent_format = 1## ⇔ 字下げ書式。
//
- ##lib/convert_html.php## の ##function parse## 入り口直後にて、
#code(diff){{
function parse(& $lines)
{
+ global $indent_format;
$this->last = & $this;
$matches = array();
+ $indent = "";
}}
-- ##$indent = "";## は字下げした深さを格納する変数。複数行プラグインで利用。
//
- 同ファイルの ##function parse## の ##while (!empty($lines))##直後にて、
#code(diff){{{{
while (! empty($lines)) {
$line = array_shift($lines);
+ // Indent extension
+ if ($indent_format)
+ {
+ preg_match('/^(\s*)(.*)$/', $line, $matches);
+ $indent = strlen($matches[1]);
+ $line = $matches[2] ;
+ }
+
+ if (rtrim($line) == '%indent') {
+ $indent_format = 1;
+ continue;
+ }
+ if (rtrim($line) == '#noindent') {
+ $indent_format = 0;
+ continue;
+ }
// Escape comments
if (substr($line, 0, 2) == '//') continue;
}}}}
-- ##$line = array_shift($lines);## でラインを切り出すため、この後に記述。
-- ##Escape comments##など全てが字下げの影響を受けるため、これらの前に記述。
-- ##if (rtrim($line) == '%indent') {...}## は字下げ書式へ切り替える疑似プラグイン。
-- ##if (rtrim($line) == '#noindent') {...}## は天突き書式へ切り替える疑似プラグイン。
//
- 同ループの中ほど、複数行ブロックプラグインにて、
#code(diff){{{{
! // Multiline-enabled Argment-keeping Block-plugin
if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
preg_match('/^#[^{]+(\{\{+)\s*$/', $line, $matches)) {
+ $delimiter = "\r";
$len = strlen($matches[1]);
- $line .= "\r"; // Delimiter
+ $line .= $delimiter;
while (! empty($lines)) {
$next_line = rtrim(array_shift($lines), "\r\n");
+ if ($indent_format)
+ {
+ preg_match('/^(\s{'.$indent.'}?)?(.*)$/', $next_line, $matches);
+ $next_line = $matches[2];
+ }
- if (preg_match('/\}{' . $len . '}/', $next_line)) {
- $line .= $next_line;
- break;
- } else {
- $line .= $next_line .= "\r"; // Delimiter
- }
+ if (preg_match('/\s*\}{' . $len . '}/', $next_line)) {
+ $line .= ltrim($next_line);
+ break;
+ } else {
+ $line .= $next_line . $delimiter;
+ }
}
}
}}}}
-- 10〜14行目は字下げ処理。##$indent## が保持しているプラグイン先頭の字下げ分のみを除去。
-- 21〜24行目は波引数の終了括弧の処理。##}## の前に空白を任意に変更。
////////////////////////////////////////////////////////////////
* 課題 [#o0fd377a]
- 「##&#;indent##」と「##&#;noindent##」による文脈の切り替えは良くない。
-- 互換性を捨て、字下げ書式に限定すべきかも。
////////////////////////////////////////////////////////////////