parseLine() 최종 공개 메소드

Parses text as single line.
final public parseLine ( Texy $texy, $s ) : void
$texy Texy
리턴 void
예제 #1
0
 /**
  * Finish invocation.
  * @return Texy\HtmlElement|FALSE
  */
 public function solve(Texy\HandlerInvocation $invocation, $content, Texy\Modifier $mod = NULL)
 {
     $texy = $this->texy;
     // find hard linebreaks
     if ($texy->mergeLines) {
         // ....
         // ... => \r means break line
         $content = Regexp::replace($content, '#\\n +(?=\\S)#', "\r");
     } else {
         $content = Regexp::replace($content, '#\\n#', "\r");
     }
     $el = new Texy\HtmlElement('p');
     $el->parseLine($texy, $content);
     $content = $el->getText();
     // string
     // check content type
     // block contains block tag
     if (strpos($content, $texy::CONTENT_BLOCK) !== FALSE) {
         $el->setName(NULL);
         // ignores modifier!
         // block contains text (protected)
     } elseif (strpos($content, $texy::CONTENT_TEXTUAL) !== FALSE) {
         // leave element p
         // block contains text
     } elseif (preg_match('#[^\\s' . Texy\Patterns::MARK . ']#u', $content)) {
         // leave element p
         // block contains only replaced element
     } elseif (strpos($content, $texy::CONTENT_REPLACED) !== FALSE) {
         $el->setName($texy->nontextParagraph);
         // block contains only markup tags or spaces or nothing
     } else {
         // if {ignoreEmptyStuff} return FALSE;
         if (!$mod) {
             $el->setName(NULL);
         }
     }
     if ($el->getName()) {
         // apply modifier
         if ($mod) {
             $mod->decorate($texy, $el);
         }
         // add <br />
         if (strpos($content, "\r") !== FALSE) {
             $key = $texy->protect('<br />', $texy::CONTENT_REPLACED);
             $content = str_replace("\r", $key, $content);
         }
     }
     $content = strtr($content, "\r\n", '  ');
     $el->setText($content);
     return $el;
 }
예제 #2
0
 /**
  * Finish invocation.
  * @return HtmlElement|string|FALSE
  */
 public function solve(Texy\HandlerInvocation $invocation, $blocktype, $s, $param, Texy\Modifier $mod)
 {
     $texy = $this->texy;
     $parser = $invocation->getParser();
     if ($blocktype === 'block/texy') {
         $el = new HtmlElement();
         $el->parseBlock($texy, $s, $parser->isIndented());
         return $el;
     }
     if (empty($texy->allowed[$blocktype])) {
         return FALSE;
     }
     if ($blocktype === 'block/texysource') {
         $s = Helpers::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = new HtmlElement();
         if ($param === 'line') {
             $el->parseLine($texy, $s);
         } else {
             $el->parseBlock($texy, $s);
         }
         $s = $el->toHtml($texy);
         $blocktype = 'block/code';
         $param = 'html';
         // to be continue (as block/code)
     }
     if ($blocktype === 'block/code') {
         $s = Helpers::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
         $s = $texy->protect($s, $texy::CONTENT_BLOCK);
         $el = new HtmlElement('pre');
         $mod->decorate($texy, $el);
         $el->attrs['class'][] = $param;
         // lang
         $el->create('code', $s);
         return $el;
     }
     if ($blocktype === 'block/default') {
         $s = Helpers::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = new HtmlElement('pre');
         $mod->decorate($texy, $el);
         $el->attrs['class'][] = $param;
         // lang
         $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
         $s = $texy->protect($s, $texy::CONTENT_BLOCK);
         $el->setText($s);
         return $el;
     }
     if ($blocktype === 'block/pre') {
         $s = Helpers::outdent($s);
         if ($s === '') {
             return "\n";
         }
         $el = new HtmlElement('pre');
         $mod->decorate($texy, $el);
         $lineParser = new Texy\LineParser($texy, $el);
         // special mode - parse only html tags
         $tmp = $lineParser->patterns;
         $lineParser->patterns = [];
         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 = html_entity_decode($s, ENT_QUOTES, 'UTF-8');
         $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
         $s = $texy->unprotect($s);
         $s = $texy->protect($s, $texy::CONTENT_BLOCK);
         $el->setText($s);
         return $el;
     }
     if ($blocktype === 'block/html') {
         $s = trim($s, "\n");
         if ($s === '') {
             return "\n";
         }
         $el = new HtmlElement();
         $lineParser = new Texy\LineParser($texy, $el);
         // special mode - parse only html tags
         $tmp = $lineParser->patterns;
         $lineParser->patterns = [];
         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 = html_entity_decode($s, ENT_QUOTES, 'UTF-8');
         $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
         $s = $texy->unprotect($s);
         return $texy->protect($s, $texy::CONTENT_BLOCK) . "\n";
     }
     if ($blocktype === 'block/text') {
         $s = trim($s, "\n");
         if ($s === '') {
             return "\n";
         }
         $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
         $s = str_replace("\n", (new HtmlElement('br'))->startTag(), $s);
         // nl2br
         return $texy->protect($s, $texy::CONTENT_BLOCK) . "\n";
     }
     if ($blocktype === 'block/comment') {
         return "\n";
     }
     if ($blocktype === 'block/div') {
         $s = Helpers::outdent($s, TRUE);
         if ($s === '') {
             return "\n";
         }
         $el = new HtmlElement('div');
         $mod->decorate($texy, $el);
         $el->parseBlock($texy, $s, $parser->isIndented());
         // TODO: INDENT or NORMAL ?
         return $el;
     }
     return FALSE;
 }