Exemplo n.º 1
0
 public function __construct($out)
 {
     parent::__construct('dl', 'dt', ':', $out[0]);
     $element = new ListElement($this->level, 'dd');
     $this->last = Element::insert($element);
     if (!empty($out[1])) {
         $this->last = $this->last->insert(ElementFactory::factory('InlineElement', null, $out[1]));
     }
 }
Exemplo n.º 2
0
 public function __construct(&$root, $text)
 {
     parent::__construct();
     $this->text = $text;
     $this->level = min(3, strspn($text, '*'));
     list($text, $this->msg_top, $this->id) = $root->getAnchor($text, $this->level);
     $this->insert(ElementFactory::factory('InlineElement', null, $text));
     $this->level++;
     // h2,h3,h4
 }
Exemplo n.º 3
0
 public function __construct($text, $param = '')
 {
     parent::__construct();
     $this->param = $param;
     if (empty($text)) {
         return;
     }
     if (substr($text, 0, 1) == '~') {
         $text = ' ' . substr($text, 1);
     }
     $this->insert(ElementFactory::factory('Inline', null, $text));
 }
Exemplo n.º 4
0
 public function __construct($tag, $tag2, $head, $text)
 {
     parent::__construct();
     $this->tag = $tag;
     $this->tag2 = $tag2;
     $this->level = min(3, strspn($text, $head));
     $text = ltrim(substr($text, $this->level));
     $element = new ListElement($this->level, $tag2);
     parent::insert($element);
     if (!empty($text)) {
         $this->last = $this->last->insert(ElementFactory::factory('InlineElement', null, $text));
     }
 }
Exemplo n.º 5
0
 public function __construct(&$root, $text)
 {
     parent::__construct();
     $head = substr($text, 0, 1);
     $this->level = min(3, strspn($text, $head));
     $text = ltrim(substr($text, $this->level));
     if ($head === '<') {
         // Blockquote close
         $level = $this->level;
         $this->level = 0;
         $this->last = $this->end($root, $level);
         if (!empty($text)) {
             $this->last = $this->last->insert(ElementFactory::factory('InlineElement', null, $text));
         }
     } else {
         $this->insert(ElementFactory::factory('InlineElement', null, $text));
     }
 }
Exemplo n.º 6
0
 public function parse($lines)
 {
     $this->last =& $this;
     $matches = array();
     while (!empty($lines)) {
         $line = array_shift($lines);
         // Escape comments
         if (substr($line, 0, 2) === '//') {
             if ($this->is_guiedit) {
                 $this->comments[] = substr($line, 2);
                 $line = '___COMMENT___';
             } else {
                 continue;
             }
         }
         // Extend TITLE by miko
         if (preg_match('/^(TITLE):(.*)$/', $line, $matches)) {
             global $newtitle;
             static $newbase;
             if (!isset($newbase)) {
                 $newbase = trim(Utility::stripHtmlTags(RendererFactory::factory($matches[2])));
                 // For BugTrack/132.
                 $newtitle = Utility::htmlsc($newbase);
             }
             continue;
         }
         if (preg_match('/^(LEFT|CENTER|RIGHT|JUSTIFY):(.*)$/', $line, $matches)) {
             // <div style="text-align:...">
             $align = new Align(strtolower($matches[1]));
             $this->last = $this->last->add($align);
             if (empty($matches[2])) {
                 continue;
             }
             $line = $matches[2];
         }
         $line = rtrim($line, "\t\r\n\v");
         // スペース以外の空白文字をトリム
         // Empty
         if (empty($line)) {
             $this->last =& $this;
             continue;
         }
         // Horizontal Rule
         if (substr($line, 0, 4) == '----') {
             $hrule = new HRule($this, $line);
             $this->insert($hrule);
             continue;
         }
         // Multiline-enabled block plugin #plugin{{ ... }}
         if (preg_match('/^#[^{]+(\\{\\{+)\\s*$/', $line, $matches)) {
             $len = strlen($matches[1]);
             $line .= self::MULTILINE_DELIMITER;
             while (!empty($lines)) {
                 $next_line = preg_replace('/[' . self::MULTILINE_DELIMITER . '\\n]*$/', '', array_shift($lines));
                 if (preg_match('/\\}{' . $len . '}/', $next_line)) {
                     $line .= $next_line;
                     break;
                 } else {
                     $line .= $next_line .= self::MULTILINE_DELIMITER;
                 }
             }
         }
         // The first character
         $head = $line[0];
         // Heading
         if ($head === '*') {
             $heading = new Heading($this, $line);
             $this->insert($heading);
             continue;
         }
         // Pre
         if ($head === ' ' || $head === "\t") {
             $pre = new Pre($this, $line);
             $this->last = $this->last->add($pre);
             continue;
         }
         // CPre (Plus!)
         if (substr($line, 0, 2) === '# ' or substr($line, 0, 2) == "#\t") {
             $sharppre = new SharpPre($this, $line);
             $this->last = $this->last->add($sharppr);
             continue;
         }
         // Line Break
         if (substr($line, -1) === '~') {
             $line = substr($line, 0, -1) . "\r";
         }
         // Other Character
         if (gettype($this->last) === 'object') {
             switch ($head) {
                 case '-':
                     $content = new UList($this, $line);
                     break;
                 case '+':
                     $content = new OList($this, $line);
                     break;
                 case '>':
                 case '<':
                     $content = new Blockquote($this, $line);
                     break;
                     // ここからはファクトリークラスを通す
                 // ここからはファクトリークラスを通す
                 case ':':
                     $content = ElementFactory::factory('DList', $this, $line);
                     break;
                 case '|':
                     $content = ElementFactory::factory('Table', $this, $line);
                     break;
                 case ',':
                     $content = ElementFactory::factory('YTable', $this, $line);
                     break;
                 case '#':
                     if ($this->is_guiedit) {
                         $content = ElementFactory::factory('PluginDummy', $this, $line);
                     } else {
                         $content = ElementFactory::factory('Plugin', $this, $line);
                     }
                     break;
                 default:
                     $content = ElementFactory::factory('InlineElement', null, $line);
                     break;
             }
             // MathJax Expression
             if (PluginRenderer::hasPlugin('mathjax')) {
                 $end_mark = '';
                 // 開始行によって終了行を判定する
                 if (substr($line, 0, 2) === '\\[') {
                     $end_mark = '\\]';
                 } else {
                     if (substr($line, 0, 6) === '\\begin') {
                         $end_mark = '\\end';
                     }
                 }
                 if ($end_mark) {
                     while (!empty($lines)) {
                         if (strpos($line, $end_mark) !== false) {
                             break;
                         }
                         $next_line = preg_replace("/[\r\n]*\$/", '', array_shift($lines));
                         $line .= "\n" . ' ' . $next_line;
                     }
                     $mathjax = new BlockPlugin(array(null, 'mathjax', $line));
                     $this->last = $this->last->add($mathjax);
                     continue;
                 }
             }
             // Default
             $this->last = $this->last->add($content);
             unset($content);
             continue;
         }
     }
 }
Exemplo n.º 7
0
 public function __construct($text, $is_template = FALSE)
 {
     parent::__construct();
     $matches = array();
     // 必ず$matchesの末尾の配列にテキストの内容が入るのでarray_popの返り値を使用する方法に変更。
     // もうすこし、マシな実装方法ないかな・・・。12/05/03
     while (preg_match(self::CELL_OPTION_MATCH_PATTERN, $text, $matches)) {
         // 内容
         $text = array_pop($matches);
         // スイッチ
         if ($matches[1]) {
             // LEFT CENTER RIGHT JUSTIFY
             $this->style['text-align'] = $matches[1];
         } else {
             if ($matches[3]) {
                 // COLOR / BGCOLOR
                 $name = $matches[2] ? 'background-color' : 'color';
                 $this->style[$name] = $matches[3];
             } else {
                 if ($matches[4]) {
                     // SIZE
                     $this->style['font-size'] = $matches[4] . 'px';
                 } else {
                     if ($matches[5]) {
                         // LANG
                         $this->lang = strtolower(Utility::htmlsc($matches[5]));
                     } else {
                         if ($matches[6]) {
                             // TOP / MIDDLE / BOTTOM
                             // http://pukiwiki.sourceforge.jp/?%E8%B3%AA%E5%95%8F%E7%AE%B14%2F540
                             $this->style['vertical-align'] = $matches[6];
                         } else {
                             if ($matches[7]) {
                                 // NOWRAP
                                 // http://pukiwiki.sourceforge.jp/dev/?PukiWiki%2F1.4%2F%A4%C1%A4%E7%A4%C3%A4%C8%CA%D8%CD%F8%A4%CB%2F%C9%BD%C1%C8%A4%DF%A4%C7nowrap%A4%F2%BB%D8%C4%EA%A4%B9%A4%EB
                                 $this->style['white-space'] = 'nowrap';
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($is_template && is_numeric($text)) {
         $this->style['width'] = $text . 'px;';
     }
     if (preg_match("/\\S+/", $text) === false) {
         // セルが空だったり、空白文字しか残らない場合は、空欄のセルとする。(HTMLではタブやスペースも削除)
         $text = '';
         $this->is_blank = true;
     } else {
         if ($text === '>') {
             $this->colspan = 0;
         } else {
             if ($text === '~') {
                 $this->rowspan = 0;
             } else {
                 if (substr($text, 0, 1) === '~') {
                     $this->tag = 'th';
                     $text = substr($text, 1);
                 }
             }
         }
     }
     if (!empty($text) && $text[0] === '#') {
         // Try using Div class for this $text
         $obj = ElementFactory::factory('Div', $this, $text);
         if ($obj instanceof Paragraph) {
             $obj = $obj->elements[0];
         }
     } else {
         $obj = ElementFactory::factory('InlineElement', null, $text);
     }
     $this->insert($obj);
 }