includes/wikiengine/parse_mediawiki.php
author Dan
Fri, 18 Dec 2009 05:12:02 -0500
changeset 1173 b5b8e7ab0914
parent 1156 417e66a664d0
child 1174 def792dd9b1b
permissions -rw-r--r--
Comments (AJAX): Now paginated server side. Fixes issue 2.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
     1
<?php
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
     2
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
     3
/*
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents: 1078
diff changeset
     5
 * Copyright (C) 2006-2009 Dan Fuhry
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
     6
 *
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
     7
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
     8
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
     9
 *
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    11
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    12
 */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    13
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    14
class Carpenter_Parse_MediaWiki
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    15
{
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    16
  public $rules = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    17
    'bold'   => "/'''(.+?)'''/",
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    18
    'italic' => "/''(.+?)''/",
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    19
    'underline' => '/__(.+?)__/',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    20
    'externalwithtext' => '#\[((?:https?|irc|ftp)://.+?) (.+?)\]#',
1106
01315acbc22b Wikitext: added horizontal rule support
Dan
parents: 1081
diff changeset
    21
    'externalnotext' => '#\[((?:https?|irc|ftp)://.+?)\]#',
1156
417e66a664d0 Wikitext parser: re-added mailto support
Dan
parents: 1138
diff changeset
    22
    'mailtonotext' => '#\[mailto:([^ \]]+?)\]#',
417e66a664d0 Wikitext parser: re-added mailto support
Dan
parents: 1138
diff changeset
    23
    'mailtowithtext' => '#\[mailto:([^ \]]+?) (.+?)\]#',
1106
01315acbc22b Wikitext: added horizontal rule support
Dan
parents: 1081
diff changeset
    24
    'hr' => '/^[-]{4,} *$/m'
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    25
  );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    26
  
1078
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
    27
  private $blockquote_rand_id;
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
    28
  
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    29
  public function lang(&$text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    30
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    31
    global $lang;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    32
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    33
    preg_match_all('/<lang (?:code|id)="([a-z0-9_-]+)">([\w\W]+?)<\/lang>/', $text, $langmatch);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    34
    foreach ( $langmatch[0] as $i => $match )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    35
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    36
      if ( $langmatch[1][$i] == $lang->lang_code )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    37
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    38
        $text = str_replace_once($match, $langmatch[2][$i], $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    39
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    40
      else
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    41
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    42
        $text = str_replace_once($match, '', $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    43
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    44
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    45
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    46
    return array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    47
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    48
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    49
  public function templates(&$text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    50
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    51
    $template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU";
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    52
    $i = 0;
1054
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
    53
    while ( preg_match($template_regex, $text, $match) )
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    54
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    55
      $i++;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    56
      if ( $i == 5 )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    57
        break;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    58
      $text = RenderMan::include_templates($text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    59
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    60
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    61
    return array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    62
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    63
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    64
  public function heading(&$text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    65
  {
1031
8a4b75e73137 Wiki formatting: Headings: tolerate spaces after line; added disable_rule method (required for rev. 1029)
Dan
parents: 1027
diff changeset
    66
    if ( !preg_match_all('/^(={1,6}) *(.+?) *\\1 *$/m', $text, $results) )
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    67
      return array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    68
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    69
    $headings = array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    70
    foreach ( $results[0] as $i => $match )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    71
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    72
      $headings[] = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    73
          'level' => strlen($results[1][$i]),
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    74
          'text' => $results[2][$i]
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    75
        );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    76
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    77
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    78
    $text = Carpenter::tokenize($text, $results[0]);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    79
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    80
    return $headings;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    81
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    82
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    83
  public function multilist(&$text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    84
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    85
    // Match entire lists
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    86
    $regex = '/^
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    87
                ([:#\*])+     # Initial list delimiter
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    88
                [ ]*
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    89
                .+?
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    90
                (?:
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    91
                  \r?\n
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    92
                  (?:\\1|[ ]{2,})
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    93
                  [ ]*
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    94
                  .+?)*
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    95
                $/mx';
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    96
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    97
    if ( !preg_match_all($regex, $text, $lists) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    98
      return array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
    99
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   100
    $types = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   101
        '*' => 'unordered',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   102
        '#' => 'ordered',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   103
        ':' => 'indent'
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   104
      );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   105
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   106
    $pieces = array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   107
    foreach ( $lists[0] as $i => $list )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   108
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   109
      $token = $lists[1][$i];
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   110
      $piece = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   111
          'type' => $types[$token],
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   112
          'items' => array()
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   113
        );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   114
      
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   115
      // convert windows newlines to unix
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   116
      $list = str_replace("\r\n", "\n", $list);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   117
      $items_pre = explode("\n", $list);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   118
      $items = array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   119
      // first pass, go through and combine items that are newlined
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   120
      foreach ( $items_pre as $item )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   121
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   122
        if ( substr($item, 0, 1) == $token )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   123
        {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   124
          $items[] = $item;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   125
        }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   126
        else
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   127
        {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   128
          // it's a continuation of the previous LI. Don't need to worry about
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   129
          // undefined indices here since the regex should filter out all invalid
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   130
          // markup. Just append this line to the previous.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   131
          $items[ count($items) - 1 ] .= "\n" . trim($item);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   132
        }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   133
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   134
      
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   135
      // second pass, separate items and tokens
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   136
      unset($items_pre);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   137
      foreach ( $items as $item )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   138
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   139
        // get the depth
1073
b19a9bcb6a45 More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents: 1054
diff changeset
   140
        $itemtoken = preg_replace('/^([#:\*]+).*$/s', '$1', $item);
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   141
        // get the text
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   142
        $itemtext = trim(substr($item, strlen($itemtoken)));
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   143
        $piece['items'][] = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   144
            // depth starts at 1
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   145
            'depth' => strlen($itemtoken),
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   146
            'text' => $itemtext
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   147
          );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   148
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   149
      $pieces[] = $piece;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   150
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   151
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   152
    $text = Carpenter::tokenize($text, $lists[0]);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   153
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   154
    return $pieces;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   155
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   156
  
1073
b19a9bcb6a45 More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents: 1054
diff changeset
   157
  public function blockquote(&$text)
b19a9bcb6a45 More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents: 1054
diff changeset
   158
  {
1078
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   159
    $rand_id = hexencode(AESCrypt::randkey(16), '', '');
1073
b19a9bcb6a45 More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents: 1054
diff changeset
   160
    
1078
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   161
    while ( preg_match_all('/^(?:(>+) *.+(?:\r?\n|$))+/m', $text, $quotes) )
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   162
    {
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   163
      foreach ( $quotes[0] as $quote )
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   164
      {
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   165
        $piece = trim(preg_replace('/^> */m', '', $quote));
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   166
        $text = str_replace_once($quote, "{blockquote:$rand_id}\n$piece\n{/blockquote:$rand_id}\n", $text);
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   167
      }
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   168
    }
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   169
    //die('<pre>' . htmlspecialchars($text) . '</pre>');
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   170
    
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   171
    $this->blockquote_rand_id = $rand_id;
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   172
  }
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   173
  
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   174
  public function blockquotepost(&$text)
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   175
  {
67a4c839c7e1 Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
parents: 1073
diff changeset
   176
    return $this->blockquote_rand_id;
1073
b19a9bcb6a45 More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents: 1054
diff changeset
   177
  }
b19a9bcb6a45 More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents: 1054
diff changeset
   178
  
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   179
  public function paragraph(&$text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   180
  {
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   181
    // The trick with paragraphs is to not turn things into them when a block level element already wraps the block of text.
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   182
    // First we need a list of block level elements (http://htmlhelp.com/reference/html40/block.html + some Enano extensions)
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   183
    $blocklevel = 'address|blockquote|center|code|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|table|ul|tr|td|th|tbody|thead|tfoot';
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   184
    
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   185
    // Wrap all block level tags
1073
b19a9bcb6a45 More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents: 1054
diff changeset
   186
    RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);
1138
a7b490f0c418 parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
parents: 1134
diff changeset
   187
    
1127
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   188
    // I'm not sure why I had to go through all these alternatives. Trying to bring it
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   189
    // all down to one by ?'ing subpatterns was causing things to return empty and throwing
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   190
    // errors in the parser. Eventually, around ~3:57AM I just settled on this motherf---er
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   191
    // of a regular expression.
1138
a7b490f0c418 parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
parents: 1134
diff changeset
   192
    
a7b490f0c418 parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
parents: 1134
diff changeset
   193
    // FIXME: This regexp triggers a known PHP stack size issue under win32 and possibly
a7b490f0c418 parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
parents: 1134
diff changeset
   194
    // other platforms (<http://bugs.php.net/bug.php?id=47689>). The workaround is going to
a7b490f0c418 parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
parents: 1134
diff changeset
   195
    // involve writing our own parser that takes care of recursion without using the stack,
a7b490f0c418 parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
parents: 1134
diff changeset
   196
    // which is going to be a bitch, and may not make it in until Caoineag RCs.
a7b490f0c418 parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
parents: 1134
diff changeset
   197
    
1127
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   198
    $regex = ";
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   199
              <($blocklevel)
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   200
              (?:
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   201
                # self closing, no attributes
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   202
                [ ]*/>
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   203
              |
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   204
                # self closing, attributes
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   205
                [ ][^>]+? />
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   206
              |
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   207
                # with inner text, no attributes
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   208
                >
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   209
                (?: (?R) | .*? )*</\\1>
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   210
              |
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   211
                # with inner text and attributes
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   212
                [ ][^>]+?     # attributes
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   213
                >
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   214
                (?: (?R) | .*? )*</\\1>
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   215
              )
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   216
                ;sx";
4b858862c35c More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
parents: 1106
diff changeset
   217
                
1131
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   218
    // oh. and we're using this tokens thing because for identical matches, the first match will
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   219
    // get wrapped X number of times instead of all matches getting wrapped once; replacing each
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   220
    // with a unique token id remedies this
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   221
    
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   222
    $tokens = array();
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   223
    $rand_id = sha1(microtime() . mt_rand());
1134
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   224
    
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   225
    // Temporary hack to fix crashes under win32. Sometime I'll write a loop based
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   226
    // parser for this whole section. Maybe. Perhaps the Apache folks will fix their
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   227
    // Windows binaries first.
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   228
    if ( PHP_OS == 'WIN32' || PHP_OS == 'WINNT' )
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   229
    {
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   230
      $regex = str_replace("(?: (?R) | .*? )*", "(?: .*? )", $regex);
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   231
    }
1130
c308b471ed82 OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
parents: 1127
diff changeset
   232
    if ( preg_match_all($regex, $text, $matches) )
c308b471ed82 OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
parents: 1127
diff changeset
   233
    {
1131
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   234
      foreach ( $matches[0] as $i => $match )
1130
c308b471ed82 OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
parents: 1127
diff changeset
   235
      {
1131
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   236
        $text = str_replace_once($match, "{_pb_:$rand_id:$i}", $text);
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   237
        $tokens[$i] = '<_paragraph_bypass>' . $match . '</_paragraph_bypass>';
1130
c308b471ed82 OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
parents: 1127
diff changeset
   238
      }
c308b471ed82 OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
parents: 1127
diff changeset
   239
    }
c308b471ed82 OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
parents: 1127
diff changeset
   240
    
1131
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   241
    foreach ( $tokens as $i => $match )
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   242
    {
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   243
      $text = str_replace_once("{_pb_:$rand_id:$i}", $match, $text);
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   244
    }
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   245
    
adfbe522c95f Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
parents: 1130
diff changeset
   246
    // die('<pre>' . htmlspecialchars($text) . '</pre>');
1134
4fdd92da4fe8 Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
parents: 1131
diff changeset
   247
	
1073
b19a9bcb6a45 More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents: 1054
diff changeset
   248
    RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw, true);
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   249
    
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   250
    // This is potentially a hack. It allows the parser to stick in <_paragraph_bypass> tags
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   251
    // to prevent the paragraph parser from interfering with pretty HTML generated elsewhere.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   252
    RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   253
    
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   254
    $startcond = "(?!(?:[\\r\\n]|\{_paragraph_bypass:[a-f0-9]{32}:[0-9]+\}|[ ]*<\/?(?:$blocklevel)(?: .+>|>)))";
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   255
    $regex = "/^
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   256
                $startcond        # line start condition - do not match if the line starts with the condition above
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   257
                .+?               # body text
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   258
                (?:
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   259
                  \\n             # additional lines
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   260
                  $startcond      # make sure of only one newline in a row, and end the paragraph if a new line fails the start condition
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   261
                  .*?
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   262
                )*                # keep going until it fails
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   263
              $
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   264
              /mx";
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   265
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   266
    if ( !preg_match_all($regex, $text, $matches) )
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   267
    {
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   268
      RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw);
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   269
      return array();
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   270
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   271
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   272
    // Debugging :)
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1031
diff changeset
   273
    // die('<pre>' . htmlspecialchars($text) . "\n-----------------------------------------------------------\n" . htmlspecialchars(print_r($matches, true)) . '</pre>');
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   274
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   275
    // restore stripped
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   276
    RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   277
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   278
    // tokenize
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   279
    $text = Carpenter::tokenize($text, $matches[0]);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   280
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   281
    return $matches[0];
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   282
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   283
}
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   284
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   285
function parser_mediawiki_xhtml_image($text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   286
{
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   287
  $text = RenderMan::process_image_tags($text, $taglist);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   288
  $text = RenderMan::process_imgtags_stage2($text, $taglist);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   289
  return $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   290
}
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   291
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   292
function parser_mediawiki_xhtml_tables($text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   293
{
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   294
  return process_tables($text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   295
}
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
diff changeset
   296