示例#1
0
 function parse(&$lines)
 {
     $this->last =& $this;
     $matches = array();
     $last_level = 0;
     while (!empty($lines)) {
         $line = rtrim(array_shift($lines), "\r\n");
         $this->comment = false;
         // Empty
         if ($line === '') {
             $this->last =& $this;
             $last_level = 0;
             continue;
         }
         // Escape comments
         //if (substr($line, 0, 2) == '//') continue;
         if (substr($line, 0, 2) === '//') {
             $this->comment = true;
             $line = ' ' . $line;
         }
         // The first character
         $head = $line[0];
         if ($head === ',') {
             $this->comment = true;
             $line = ' ' . $line;
             $head = ' ';
         }
         // LEFT, CENTER, RIGHT
         if ($head === 'R' || $head === 'C' || $head === 'L') {
             if (preg_match('/^(LEFT|CENTER|RIGHT):(.*)$/', $line, $matches)) {
                 // <div style="text-align:...">
                 $this->last =& $this->last->add(new AlignEx(strtolower($matches[1])));
                 if ($matches[2] === '') {
                     continue;
                 }
                 $line = $matches[2];
                 $head = $line[0];
             }
         }
         switch ($head) {
             // Horizontal Rule
             case '-':
                 if (preg_match('/-{4,}$/', $line)) {
                     $this->insert(new HRuleEx($this, $line));
                     $last_level = 0;
                     continue 2;
                 }
                 break;
                 // Multiline-enabled block plugin
             // Multiline-enabled block plugin
             case '#':
                 if (!PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK && preg_match('/^#[^{]+(\\{\\{+)\\s*$/', $line, $matches)) {
                     $len = strlen($matches[1]);
                     $line .= "\r";
                     // Delimiter
                     while (!empty($lines)) {
                         $next_line = preg_replace("/[\r\n]*\$/", '', array_shift($lines));
                         if (preg_match('/\\}{' . $len . '}/', $next_line)) {
                             $line .= $next_line;
                             break;
                         } else {
                             $line .= $next_line .= "\r";
                             // Delimiter
                         }
                     }
                 }
                 break;
                 // HeadingEx
             // HeadingEx
             case '*':
                 $this->insert(new HeadingEx($this, $line));
                 $last_level = 0;
                 continue 2;
                 break;
                 // PreEx
             // PreEx
             case ' ':
             case "\t":
                 $this->last =& $this->last->add(new PreEx($this, $line));
                 continue 2;
                 break;
                 // <, <<, <<< only to escape blockquote.
             // <, <<, <<< only to escape blockquote.
             case '<':
                 if ($head === '<' && !preg_match('/^<{1,3}\\s*$/', $line)) {
                     $head = '';
                 }
                 break;
         }
         // Line Break
         if (substr($line, -1) === '~') {
             $line = substr($line, 0, -1) . "\r";
         }
         // Other Character
         if (isset($this->classes[$head])) {
             $classname = $this->classes[$head];
             $this_level = strspn($line, $head);
             if ($this_level - $last_level > 1) {
                 for ($_lev = $last_level + 1; $_lev < $this_level; $_lev++) {
                     $this->last =& $this->last->add(new $classname($this, str_repeat($head, $_lev) . ""));
                 }
             }
             $last_level = $this_level;
             $this->last =& $this->last->add(new $classname($this, $line));
             continue;
         }
         // Other Character
         if (isset($this->factories[$head])) {
             if ($head === ':') {
                 $this_level = strspn($line, $head);
                 if ($this_level - $last_level > 1) {
                     for ($_lev = $last_level + 1; $_lev < $this_level; $_lev++) {
                         $this->last =& $this->last->add(Factory_DListEx($this, ':|'));
                     }
                 }
                 $last_level = $this_level;
             }
             $factoryname = 'Factory_' . $this->factories[$head];
             $this->last =& $this->last->add($factoryname($this, $line));
             continue;
         }
         // Default
         $this->last =& $this->last->add(Factory_InlineEx($line));
     }
 }
示例#2
0
 function parse(&$lines)
 {
     $this->last =& $this;
     $matches = array();
     while (!empty($lines)) {
         $line = array_shift($lines);
         // Escape comments
         if (substr($line, 0, 2) == '//') {
             $this->comments[] = substr($line, 2);
             $line = '___COMMENT___';
         }
         if (preg_match('/^(LEFT|CENTER|RIGHT):(.*)$/', $line, $matches)) {
             // <div style="text-align:...">
             $this->last =& $this->last->add(new AlignEx(strtolower($matches[1])));
             if ($matches[2] == '') {
                 continue;
             }
             $line = $matches[2];
         }
         $line = rtrim($line, "\r\n");
         // Empty
         if ($line == '') {
             $this->last =& $this;
             continue;
         }
         // Horizontal Rule
         if (substr($line, 0, 4) == '----') {
             $this->insert(new HRuleEx($this, $line));
             continue;
         }
         // Multiline-enabled block plugin
         if (!PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK && preg_match('/^#[^{]+(\\{\\{+)\\s*$/', $line, $matches)) {
             $len = strlen($matches[1]);
             $line .= "\r";
             // Delimiter
             while (!empty($lines)) {
                 $next_line = preg_replace("/[\r\n]*\$/", '', array_shift($lines));
                 // UPK
                 $next_line = htmlspecialchars($next_line);
                 if (preg_match('/\\}{' . $len . '}/', $next_line)) {
                     $line .= $next_line;
                     break;
                 } else {
                     $line .= $next_line .= "\r";
                     // Delimiter
                 }
             }
         }
         // The first character
         $head = $line[0];
         // HeadingEx
         if ($head == '*') {
             $this->insert(new HeadingEx($this, $line));
             continue;
         }
         // PreEx
         if ($head == ' ' || $head == "\t") {
             $this->last =& $this->last->add(new PreEx($this, $line));
             continue;
         }
         // Line Break
         if (substr($line, -1) == '~') {
             $line = substr($line, 0, -1) . "\r";
         }
         // Other Character
         if (isset($this->classes[$head])) {
             $classname = $this->classes[$head];
             $this->last =& $this->last->add(new $classname($this, $line));
             continue;
         }
         // Other Character
         if (isset($this->factories[$head])) {
             $factoryname = 'Factory_' . $this->factories[$head];
             $this->last =& $this->last->add($factoryname($this, $line));
             continue;
         }
         // Default
         $this->last =& $this->last->add(Factory_InlineEx($line));
     }
 }