예제 #1
0
 public function addTextBlock(TextBlock $block)
 {
     if ($block->isEmpty()) {
         return;
     }
     $block->setStartOffset($this->offset);
     $block->setEndOffset($this->offset);
     $this->textBlocks[] = $block;
     $this->offset++;
 }
예제 #2
0
파일: Console.php 프로젝트: Etskh/Jaya-CMS
 public function printc($str)
 {
     // TODO: If $this->_colourize is false, strip out the colour
     //
     $text = TextBlock::Parse($str, 'Console::getConsoleColourFromHex', "", "");
     print $text->string;
 }
예제 #3
0
 protected function node(\DOMNode $element, $level = 0, $isAnchor = false)
 {
     $tag = null;
     if ($element->nodeType == XML_ELEMENT_NODE) {
         $tag = strtolower($element->tagName);
         if ($tag == 'body') {
             $this->isBody = true;
         }
         $this->isTitle = 'title' == $tag;
     }
     if ($this->isBody) {
         if ($element->nodeType == XML_ELEMENT_NODE) {
             if ('a' == $tag) {
                 $href = $element->attributes->getNamedItem('href');
                 $isAnchor = $href ? $href->nodeValue : false;
             } else {
                 if ($this->textBlock) {
                     $this->textDocument->addTextBlock($this->textBlock);
                 }
                 $labels = isset($this->labels[$tag]) ? $this->labels[$tag] : [];
                 $this->textBlock = new TextBlock($level, $labels);
             }
         } else {
             if ($element->nodeType == XML_TEXT_NODE) {
                 $this->textBlock->addText($element->data, $isAnchor);
             }
         }
     } else {
         if ($this->isTitle) {
             if ($element->nodeType == XML_TEXT_NODE) {
                 $this->title .= $element->data;
             }
         }
     }
     if ($element->childNodes) {
         foreach ($element->childNodes as $node) {
             $this->node($node, $level + 1, $isAnchor);
         }
     }
 }
예제 #4
0
 public function mergeNext(TextBlock $block)
 {
     $this->text .= "\n" . $block->getText();
     $this->texts = $this->texts + $this->getTexts();
     $this->wordCount += $block->getWordCount();
     $this->linkCount += $block->getLinkCount();
     $this->linkWordCount = $block->getLinkWordCount();
     $this->startOffset = min($this->startOffset, $block->getStartOffset());
     $this->endOffset = max($this->endOffset, $block->getEndOffset());
     $this->isContent = $this->isContent || $block->isContent();
     $this->labels = $this->labels + $block->getLabels();
     $this->level = min($this->level, $block->getLevel());
 }
예제 #5
0
 /**
  * Constructs a list item block.
  *
  * @param string  $text    the unformatted text
  * @param array   $spans   an array of \Prismic\Fragment\Span\SpanInterface objects that contain the formatting (em, strong, links, ...)
  * @param boolean $ordered true if part of an ordered list, false if unordered
  * @param string  $label   can be null
  */
 public function __construct($text, $spans, $ordered, $label = null)
 {
     $this->ordered = $ordered;
     parent::__construct($text, $spans, $label);
 }
예제 #6
0
<?php

include "ignition/ignition.php";
?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
</head>
<body>
	<h1>Textblock 1</h1>
	<?php 
RawTextBlock::show('test');
?>

	<h1>Textblock 2</h1>
	<?php 
TextBlock::show('test2');
?>
</body>
</html>
예제 #7
0
 /**
  * Constructs an heading block.
  *
  * @param string $text  the unformatted text
  * @param array  $spans an array of \Prismic\Fragment\Span\SpanInterface objects that contain the formatting (em, strong, links, ...)
  * @param string $level the heading's level
  * @param string $label may be null
  */
 public function __construct($text, $spans, $level, $label = NULL)
 {
     $this->level = $level;
     parent::__construct($text, $spans, $label);
 }
 function flushBlock()
 {
     if ($this->inBody === 0) {
         if ($this->lastStartTag === 'TITLE') {
             $this->text = '';
             $this->token = '';
             return;
         }
     }
     $length = strlen($this->token);
     if ($length === 0) {
         return;
     } else {
         if ($length === 1) {
             if ($this->sbLastWasWhitespace) {
                 $this->text = '';
                 $this->token = '';
                 return;
             }
         }
     }
     $tokens = explode(' ', $this->token);
     $numWords = 0;
     $numLinkedWords = 0;
     $numWrappedLines = 0;
     $currentLineLength = -1;
     // don't count the first space
     $maxLineLength = 80;
     $numTokens = 0;
     $numWordsCurrentLine = 0;
     foreach ($tokens as $xToken) {
         if ($xToken === $this->ANCHOR_TEXT_START) {
             $this->inAnchorText = true;
         } else {
             if ($xToken === $this->ANCHOR_TEXT_END) {
                 $this->inAnchorText = false;
             } else {
                 if ($this->isWord($xToken)) {
                     $numTokens++;
                     $numWords++;
                     $numWordsCurrentLine++;
                     if ($this->inAnchorText) {
                         $numLinkedWords++;
                     }
                     $tokenLength = strlen($xToken);
                     $currentLineLength += $tokenLength + 1;
                     if ($currentLineLength > $maxLineLength) {
                         $numWrappedLines++;
                         $currentLineLength = $tokenLength;
                         $numWordsCurrentLine = 1;
                     }
                 } else {
                     $numTokens++;
                 }
             }
         }
     }
     if ($numTokens === 0 || $numWords === 0) {
         return;
     }
     $numWordsInWrappedLines = 0;
     if ($numWrappedLines == 0) {
         $numWordsInWrappedLines = $numWords;
         $numWrappedLines = 1;
     } else {
         $numWordsInWrappedLines = $numWords - $numWordsCurrentLine;
     }
     $tb = new TextBlock();
     if ($this->linkCount > 0) {
         $tb->numWordsInAnchorText = $this->linkCount;
     } else {
         $tb->numWordsInAnchorText = 0;
     }
     $tb->text = $this->text;
     $tb->currentContainedTextElements = $this->currentContainedTextElements;
     $tb->numWords = $numWords;
     $tb->numWordsInWrappedLines = $numWordsInWrappedLines;
     $tb->numWrappedLines = $numWrappedLines;
     $tb->offsetBlocksStart = $this->offsetBlocks;
     $tb->offsetBlocksEnd = $this->offsetBlocks;
     $this->currentContainedTextElements = array();
     $this->offsetBlocks++;
     $this->text = '';
     $this->token = '';
     $tb->tagLevel = $this->blockTagLevel;
     $tb->calculateDensities();
     $this->textBlocks[] = $tb;
     $this->blockTagLevel = -1;
     $this->linkCount = 0;
 }