方針

''〜''」や「'''〜'''」のような、同じ記号を2文字または3文字使って修飾部を挟む書式は Wiki の代表的な書式である。ネコヰキではこれをネイティブ書式と呼ぶ。一方、PukiWikiでは「&〜;」や「#〜;」などのプラグインを導入することにより機能拡張を容易にした。サ行変格活用の如く、書式としては例外的ではあるが、用例の数は断然多い。ネコヰキではこれをプラグイン書式と呼ぶ。

プラグイン書式の弱点は、開始記号と終了記号が「''〜''」のように同じでもなければ、「((〜))」のように対にもなってないこと、そしてプラグイン名はテキストであるため文書に埋もれやすいことである。このため、良く使うプラグインはネイティブ書式にしたい。

ここで、プラグインのエイリアスとしてネイティブ書式を扱うため、このような書式をネイティブエイリアスと呼ぶことにする。ネコヰキの性質上、当面は数式とコードの2つのプラグインのネイティブエイリアスのみを導入する。

書式は、2文字と3文字でインラインプラグインとブロックプラグインを使い分ける。引数の展開/保持は対応するプラグイン書式に準ずる。

仕様

書式文字を「@」、対応するプラグイン名を「plugin」とする。

単一行インラインプラグイン
@@〜@@」は「&plugin(〜);」または「&plugin{〜};」と等価である。機能的違いは引数の展開/保持。どっちになるかはプラグインの性質次第。
複数行インラインプラグイン
@@ …
〜
@@
$plugin(…){{{{{{{{{{{{{{{{
〜
}}}}}}}}}}}}}}}};
と等価である。
複数行ブロックプラグイン
@@@ …
〜
@@@
#plugin(…){{{{{{{{{{{{{{{{
〜
}}}}}}}}}}}}}}}}
と等価である。

数式プラグインの場合、書式文字は「$」、プラグイン名は「eq」。書式文字は TeX のインライン数式モード「$〜$」に由来。用例は書式/数式を参照。

コードプラグインの場合、書式文字は「#」、プラグイン名は「code」。書式文字は、「#」の形が等幅表示のための桝目からの連想。また、C言語で、別言語であるプリプロセッサのコードを埋め込むときに用いられることからの連想。用例は書式/コードを参照。

実装

単一行インラインプラグイン

  • lib/make_link.phpclass InlineConverterfunction InlineConverter にて、
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
    
         function InlineConverter($converters = NULL, $excludes = NULL)
         {
             if ($converters === NULL) {
                 $converters = array(
                     'plugin',        // Inline plugins
        +            'eq',            // eq plugin
        +            'code',          // code plugin
                     'escape',        // Escapes
                     'note',          // Footnotes
                     ……
    
  • lib/make_link.phpclass Link_plugin の後に以下を追加。
      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
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
    
        // Native-alias Plugin
        class Link_plugin_alias extends Link_plugin
        {
            var $name    = 'echo';  // プラグイン名
            var $pattern = '';      // 正規表現 Link_plugin に対応させるため、
                                    // $matches[1] = plain 
                                    // $matches[2] = plugin name
                                    // $matches[3] = parameter
                                    // $matches[4] = body // 独自拡張 // 引数展開
            
            function Link_eq($start)
            {
                parent::Link_plugin($start);
            }
            
            function get_pattern()
            {
                return $this->pattern;
            }
            
            function get_count()
            {
                return 4;
            }
            
            function set($arr, $page)
            {
                list(, $this->plain, , $this->param, $body) = $this->splice($arr);
                return parent::setParam($page, $this->name, $body, 'plugin');
            }
        }
        // Native-alias for &eq plugin
        class Link_eq extends Link_plugin_alias
        {
            var $name    = 'eq';
            var $pattern = '\$\$(()(.+?)())\$\$';   // no name, no body
        }
        // Native-alias for &code plugin
        class Link_code extends Link_plugin_alias
        {
            var $name    = 'code';
            var $pattern = '\#\#(()()(.+?))\#\#';   // no name, no parameter
        } 
    • Link_plugin_alias は基底クラス。直接生成されることはない。
    • eq は引数保持、code は引数展開。

複数行インラインプラグイン

  • lib/convert_html.phpclass Bodyfunction parse にて、 複数行プラグインの後あたり。
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
    
            // Native-alias for $eq-Plugin
            $pattern = '/^\s*\$\$\s*$/';
            if (preg_match($pattern, $line)) {
                $delimiter = "\r";
                $line = '&eq{{{{{{{{{{{{{{{{'.$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($pattern, $next_line)) {
                        $line .= ltrim('}}}}}}}}}}}}}}}};');
                        break;
                    } else {
                        $line .= $next_line . $delimiter;
                    }
                }
            } 
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
    
    !        // Native-alias for $code-Plugin
    !        $pattern = '/^\s*##\s*$/';
             if (preg_match($pattern, $line)) {
                 $delimiter = "\r";
    !            $line = '$code{{{{{{{{{{{{{{{{'.$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($pattern, $next_line)) {
                         $line .= ltrim('}}}}}}}}}}}}}}}};');
                         break;
                     } else {
                         $line .= $next_line . $delimiter;
                     }
                 }
             }
    
    • !」に行は、eqプラグイン に対する code プラグインの差分。

複数行ブロックプラグイン

  • lib/convert_html.phpclass Bodyfunction parse にて、 複数行プラグインの後あたり。
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
    
    !            // Native-alias for #eq-Plugin
    !            $pattern = '/^\s*\$\$\$\s*$/';
                 if (preg_match($pattern, $line)) {
                     $delimiter = "\r";
    !                $line = '#eq{{{{{{{{{{{{{{{{'.$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($pattern, $next_line)) {
                             $line .= ltrim('}}}}}}}}}}}}}}}}');
                             break;
                         } else {
                             $line .= $next_line . $delimiter;
                         }
                     }
                 }
    
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
    
    !            // Native-alias for #code-Plugin
    !            $pattern = '/^\s*###\s*(\w*)\s*$/';
    !            if (preg_match($pattern, $line, $matches)) {
                     $delimiter = "\r";
    !                $line = '#code('.$matches[1].'){{{{{{{{{{{{{{{{'.$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($pattern, $next_line)) {
                             $line .= ltrim('}}}}}}}}}}}}}}}}');
                             break;
                         } else {
                             $line .= $next_line . $delimiter;
                         }
                     }
                 }
    
    • !」に行は、それぞれの複数行インラインプラグインに対する差分。
リロード   新規 編集 解凍 差分 添付 複製 改名   初基 一覧 検索 最新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2012.0229 (水) 0805.5800 (4438d)