方針 EditToHeaderToFooter

  • ウィキには書式をエスケープする手段はない。
    • 書式ごとに手段があったりもするが、ケースバイケースで覚えにくい。
    • 実体参照というエスケープが既にあるが、スペルは覚えにくい上、未対応の記号がある。
    • 文字参照というエスケープも既にあるが、ASCIIコードは覚えにくい。
  • プラグイン形式でエスケープを導入。
    • 将来の拡張を想定し、キーボードにある記号類を全対応。
      • 「エスケープ必要か?」の事態を回避。エスケープすれば必ず通ることを保障。

仕様 EditToHeaderToFooter

  • エスケープする記号を &; で挟む。
  • エスケープされた記号は文字参照に変換
  • 例:
    • &@;@
    • &&;&
    • &;;;
    • & ;

実装 EditToHeaderToFooter

  • ファイル lib/make_link.phpclass InlineConverterfunction InlineConverter にて、新しいインライン書式を登録。
      1
      2
      3
      4
      5
      6
      7
      8
    
         function InlineConverter($converters = NULL, $excludes = NULL)
         {
             if ($converters === NULL) {
                 $converters = array(
                     'plugin',        // Inline plugins
    +                'escape',        // Escapes
                     'note',          // Footnotes
                     'url',           // URLs
    
  • 同ファイル、class Link_pluginコピーし、class Link_escape に改造。
      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
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
    
    !// Escapes
    !class Link_escape extends Link
     {
         var $pattern;
         var $plain,$param;
         
         function Link_escape($start)
         {
             parent::Link($start);
         }
         
         function get_pattern()
         {
             $this->pattern = <<<EOD
     &
     (      # (1) plain
    - (\w+) # (2) plugin name
    - (?:
    -  \(
    -   ((?:(?!\)[;{]).)*) # (3) parameter
    -  \)
    - )?
    +    ([-!"#$%&'()=~|\\`@+*;:<>?_,.\/}{\][ ^])       # (2) plugin name
     )
     EOD;
             return <<<EOD
     {$this->pattern}
    -(?:
    - \{
    -  ((?:(?R)|(?!};).)*) # (4) body
    - \}
    -)?
     ;
     EOD;
         }
         
         function get_count()
         {
    -        return 4;
    +        return 2;
         }
         
         function set($arr, $page)
         {
    -        list($all, $this->plain, $name, $this->param, $body) = $this->splice($arr);
    +        list($all, $this->plain, $name) = $this->splice($arr);
         
             // Re-get true plugin name and patameters (for PHP 4.1.2)
             $matches = array();
             if (preg_match('/^' . $this->pattern . '/x', $all, $matches)
                 && $matches[1] != $this->plain) 
                 list(, $this->plain, $name) = $matches;
    +        $body = '';
    -        return parent::setParam($page, $name, $body, 'plugin');
    +        return parent::setParam($page, $name, $body, 'escape');
         }
         
         function toString()
         {
    -        $body = ($this->body == '') ? '' : make_link($this->body);
    -        $str = FALSE;
    -        
    -        // Try to call the plugin
    -        if (exist_plugin_inline($this->name))
    -            $str = do_plugin_inline($this->name, $this->param, $body);
    -        
    -        if ($str !== FALSE) {
    -            return $str; // Succeed
    -        } else {
    -            // No such plugin, or Failed
    -            $body = (($body == '') ? '' : '{' . $body . '}') . ';';
    -            return make_line_rules(htmlspecialchars('&' . $this->plain) . $body);
    -        }
    +        return htmlspecialchars($this->name);
         }
     }
    
    初基 一覧 検索 最新 バックアップ リンク元   ヘルプ   最終更新のRSS