Esempio n. 1
0
 /**
  * Finish invocation.
  *
  * @param  TexyHandlerInvocation  handler invocation
  * @param  string   blocktype
  * @param  string   content
  * @param  string   additional parameter
  * @param  TexyModifier
  * @return TexyHtml|string|FALSE
  */
 public function solve($invocation, $blocktype, $s, $param, $mod)
 {
     $tx = $this->texy;
     $parser = $invocation->parser;
     if ($blocktype === 'block/texy') {
         $el = TexyHtml::el();
         $el->parseBlock($tx, $s, $parser->isIndented());
         return $el;
     }
     if (empty($tx->allowed[$blocktype])) {
         return FALSE;
     }
     if ($blocktype === 'block/texysource') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el();
         if ($param === 'line') {
             $el->parseLine($tx, $s);
         } else {
             $el->parseBlock($tx, $s);
         }
         $s = $el->toHtml($tx);
         $blocktype = 'block/code';
         $param = 'html';
         // to be continue (as block/code)
     }
     if ($blocktype === 'block/code') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $s = Texy::escapeHtml($s);
         $s = $tx->protect($s, Texy::CONTENT_BLOCK);
         $el = TexyHtml::el('pre');
         $mod->decorate($tx, $el);
         $el->attrs['class'][] = $param;
         // lang
         $el->create('code', $s);
         return $el;
     }
     if ($blocktype === 'block/default') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('pre');
         $mod->decorate($tx, $el);
         $el->attrs['class'][] = $param;
         // lang
         $s = Texy::escapeHtml($s);
         $s = $tx->protect($s, Texy::CONTENT_BLOCK);
         $el->setText($s);
         return $el;
     }
     if ($blocktype === 'block/pre') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('pre');
         $mod->decorate($tx, $el);
         $lineParser = new TexyLineParser($tx, $el);
         // special mode - parse only html tags
         $tmp = $lineParser->patterns;
         $lineParser->patterns = array();
         if (isset($tmp['html/tag'])) {
             $lineParser->patterns['html/tag'] = $tmp['html/tag'];
         }
         if (isset($tmp['html/comment'])) {
             $lineParser->patterns['html/comment'] = $tmp['html/comment'];
         }
         unset($tmp);
         $lineParser->parse($s);
         $s = $el->getText();
         $s = Texy::unescapeHtml($s);
         $s = Texy::escapeHtml($s);
         $s = $tx->unprotect($s);
         $s = $tx->protect($s, Texy::CONTENT_BLOCK);
         $el->setText($s);
         return $el;
     }
     if ($blocktype === 'block/html') {
         $s = trim($s, "\n");
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el();
         $lineParser = new TexyLineParser($tx, $el);
         // special mode - parse only html tags
         $tmp = $lineParser->patterns;
         $lineParser->patterns = array();
         if (isset($tmp['html/tag'])) {
             $lineParser->patterns['html/tag'] = $tmp['html/tag'];
         }
         if (isset($tmp['html/comment'])) {
             $lineParser->patterns['html/comment'] = $tmp['html/comment'];
         }
         unset($tmp);
         $lineParser->parse($s);
         $s = $el->getText();
         $s = Texy::unescapeHtml($s);
         $s = Texy::escapeHtml($s);
         $s = $tx->unprotect($s);
         return $tx->protect($s, Texy::CONTENT_BLOCK) . "\n";
     }
     if ($blocktype === 'block/text') {
         $s = trim($s, "\n");
         if ($s === '') {
             return "\n";
         }
         $s = Texy::escapeHtml($s);
         $s = str_replace("\n", TexyHtml::el('br')->startTag(), $s);
         // nl2br
         return $tx->protect($s, Texy::CONTENT_BLOCK) . "\n";
     }
     if ($blocktype === 'block/comment') {
         return "\n";
     }
     if ($blocktype === 'block/div') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('div');
         $mod->decorate($tx, $el);
         $el->parseBlock($tx, $s, $parser->isIndented());
         // TODO: INDENT or NORMAL ?
         return $el;
     }
     if ($blocktype === 'block/section') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('section');
         $mod->decorate($tx, $el);
         $el->parseBlock($tx, $s, $parser->isIndented());
         // TODO: INDENT or NORMAL ?
         return $el;
     }
     if ($blocktype === 'block/article') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('article');
         $mod->decorate($tx, $el);
         $el->parseBlock($tx, $s, $parser->isIndented());
         // TODO: INDENT or NORMAL ?
         return $el;
     }
     if ($blocktype === 'block/aside') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('aside');
         $mod->decorate($tx, $el);
         $el->parseBlock($tx, $s, $parser->isIndented());
         // TODO: INDENT or NORMAL ?
         return $el;
     }
     if ($blocktype === 'block/header') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('header');
         $mod->decorate($tx, $el);
         $el->parseBlock($tx, $s, $parser->isIndented());
         // TODO: INDENT or NORMAL ?
         return $el;
     }
     if ($blocktype === 'block/footer') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('footer');
         $mod->decorate($tx, $el);
         $el->parseBlock($tx, $s, $parser->isIndented());
         // TODO: INDENT or NORMAL ?
         return $el;
     }
     if ($blocktype === 'block/nav') {
         $s = Texy::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = TexyHtml::el('nav');
         $mod->decorate($tx, $el);
         $el->parseBlock($tx, $s, $parser->isIndented());
         // TODO: INDENT or NORMAL ?
         return $el;
     }
     return FALSE;
 }
Esempio n. 2
0
 public function patternReference($parser, $matches)
 {
     list(, $mRef) = $matches;
     $tx = $this->texy;
     $name = substr($mRef, 1, -1);
     $link = $this->getReference($name);
     if (!$link) {
         return $tx->invokeAroundHandlers('newReference', $parser, array($name));
     }
     $link->type = TexyLink::BRACKET;
     if ($link->label != '') {
         if (isset(self::$livelock[$link->name])) {
             $content = $link->label;
         } else {
             self::$livelock[$link->name] = TRUE;
             $el = TexyHtml::el();
             $lineParser = new TexyLineParser($tx, $el);
             $lineParser->parse($link->label);
             $content = $el->toString($tx);
             unset(self::$livelock[$link->name]);
         }
     } else {
         $content = $this->textualUrl($link);
         $content = $this->texy->protect($content, Texy::CONTENT_TEXTUAL);
     }
     return $tx->invokeAroundHandlers('linkReference', $parser, array($link, $content));
 }
Esempio n. 3
0
 /**
  * Parses text as single line.
  * @param  Texy
  * @param  string
  * @return void
  */
 public final function parseLine(Texy $texy, $s)
 {
     // TODO!
     // special escape sequences
     $s = str_replace(array('\\)', '\\*'), array(')', '*'), $s);
     $parser = new TexyLineParser($texy, $this);
     $parser->parse($s);
     return $parser;
 }