方針 EditToHeaderToFooter

  • Wikiは行指向のため、コードの見通しが悪くなりがち。特にリストでの改行とか、複数行プラグインとか。
  • 字下げを導入でコード可読性を改善可能。

仕様 EditToHeaderToFooter

  • 字下げ書式モードでは、行頭の空白は無視。
    • ただし、複数行プラグインの引数に対しては、プラグインの先頭行の字下げ分のみを無視。~例:
          #plugin(){{
              arg
              arg
          }}
      は、
      #plugin(){{
          arg
          arg
      }}
      と等価。
  • 疑似プラグイン #indent で字下げ書式モードに切り替え。
  • 疑似プラグイン #noindent で天突き書式モードに切り替え。
  • デフォルトは天突き書式。
  • 字下げ書式では、行頭が空白の整形済みテキストは無効。

改造 EditToHeaderToFooter

  • pukiwiki.ini.php の適当な場所にて、
      1
    
    + $indent_format = 0;
    
    • $indent_format は天突きと字下げを表すフラグ。
      • $indent_format = 0 ⇔ 天突き書式。(デフォルト)
      • $indent_format = 1 ⇔ 字下げ書式。
  • lib/convert_html.phpfunction parse 入り口直後にて、
      1
      2
      3
      4
      5
      6
      7
    
         function parse(& $lines)
         {
    +        global $indent_format;
             
             $this->last = & $this;
             $matches = array();
    +        $indent = "";
    
    • $indent = ""; は字下げした深さを格納する変数。複数行プラグインで利用。
  • 同ファイルの function parsewhile (!empty($lines))直後にて、
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
    
             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') {...} は天突き書式へ切り替える疑似プラグイン。
  • 同ループの中ほど、複数行ブロックプラグインにて、
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
    
    !            // 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行目は波引数の終了括弧の処理。} の前に空白を任意に変更。

課題 EditToHeaderToFooter

  • #indent」と「#noindent」による文脈の切り替えは良くない。
    • 互換性を捨て、字下げ書式に限定すべきかも。
    初基 一覧 検索 最新 バックアップ リンク元   ヘルプ   最終更新のRSS