Example #1
0
 /**
  * Accept a visitor.
  *
  * A quotation when it accepts a visitor needs to parse no only to visit the
  * main quotation element, but also the citation element if available
  * afterwards.
  *
  * @param T_Visitor $visitor  visitor object
  */
 function accept(T_Visitor $visitor)
 {
     parent::accept($visitor);
     if ($this->getCite()) {
         $this->getCite()->accept($visitor);
     }
 }
Example #2
0
 function testDoesNotRenderChildrenOnceLimitIsReached()
 {
     $wiki = new T_Text_Plain('some content');
     $wiki->addChild(new T_Text_Paragraph('child1'));
     $wiki->addChild(new T_Text_Header(3, 'child2'));
     $wiki->addChild(new T_Text_InternalLink('child3', '/some/path'));
     $wiki->addChild(new T_Text_InternalLink('child4', 'url'));
     $short = new T_Text_Plain('some ...');
     $test = new T_Xhtml_TextPreview(10, $this->getRootUrl());
     $ref = new T_Xhtml_Text($this->getRootUrl());
     $this->assertSame($this->getVisitorRender($short, $ref), $this->getVisitorRender($wiki, $test));
 }
Example #3
0
 /**
  * Transform plain text into a parsed formatted text object.
  *
  * @param string $value
  * @return T_Text_Plain  formatted text
  */
 function doTransform($value)
 {
     $fmt = new T_Text_Plain($value);
     if ($this->is(self::HEADER)) {
         $fmt->accept(new T_Text_HeaderLexer());
     }
     if ($this->is(self::QUOTE)) {
         $fmt->accept(new T_Text_QuoteLexer());
     }
     if ($this->is(self::TABLE)) {
         $fmt->accept(new T_Text_TableLexer());
     }
     if ($this->is(self::DIVIDER)) {
         $fmt->accept(new T_Text_DividerLexer());
     }
     // ^ dividers must be lexed *after* tables, and this is safe enough as
     //   at this point no T_Text_Plain items are table cell children
     if ($this->is(self::RESOURCE)) {
         $fmt->accept(new T_Text_ResourceLexer());
     }
     if ($this->is(self::ORDERED_LIST | self::UNORDERED_LIST)) {
         $fmt->accept(new T_Text_ListLexer($this->mode));
     }
     if ($this->is(self::PARAGRAPH)) {
         $fmt->accept(new T_Text_ParagraphLexer());
     }
     if ($this->is(self::LINK)) {
         $fmt->accept(new T_Text_LinkLexer());
     }
     if ($this->is(self::RESOURCE)) {
         $fmt->accept(new T_Text_ResourceLexer());
     }
     // ^ called twice to handle 1st time standalone resources, and
     //   2nd time resources embedded in links or list items for example
     if ($this->is(self::EMPH)) {
         $fmt->accept(new T_Text_EmphLexer());
     }
     if ($this->is(self::SUPERSUB)) {
         $fmt->accept(new T_Text_SuperSubscriptLexer());
     }
     return $fmt;
 }
Example #4
0
 /**
  * Returns original formatted text.
  *
  * @return string  origianl formatting
  */
 function __toString()
 {
     return trim(parent::__toString()) . EOL . EOL;
 }
 function testAlternativeUsesOfHatsAndUnderscoreRemainUnaffected()
 {
     $unaffected = array("Followed by space ^ ", "Followed by nothing ^", "Followed by space _ ", "Followed by nothing _");
     foreach ($unaffected as $str) {
         $element = new T_Text_Plain($str);
         $element->accept(new T_Text_SuperSubscriptLexer());
         $expected = new T_Text_Plain($str);
         $this->assertEquals($expected, $element, "failed on '{$str}'");
     }
 }
Example #6
0
 function testAlternativeUsesOfDashesRemainsUnaffected()
 {
     $unaffected = array("---", "----- ----- -----", "---- some text");
     foreach ($unaffected as $str) {
         $element = new T_Text_Plain($str);
         $element->accept(new T_Text_DividerLexer());
         $expected = new T_Text_Plain($str);
         $this->assertEquals($expected, $element, "failed on {$str}");
     }
 }
Example #7
0
 /**
  * Visit a formatted text node.
  *
  * @param T_Text_Plain $node
  */
 function visitTextPlain(T_Text_Plain $node)
 {
     $this->xhtml .= $node->getContent($this->filter);
 }
Example #8
0
 function testLinksParsedInChildElement()
 {
     $expected = new T_Text_Plain('parent');
     $expected->addChild(new T_Text_Plain(), 'nest');
     $expected->nest->addChild(new T_Text_ExternalLink('content', 'http://example.com'));
     $element = new T_Text_Plain('parent');
     $element->addChild(new T_Text_Plain('[http://example.com content]'), 'nest');
     $element->accept(new T_Text_LinkLexer());
     $this->assertEquals($expected, $element);
 }
Example #9
0
 function testParagraphsParsedInChildElement()
 {
     $expected = new T_Text_Plain();
     $expected->addChild(new T_Text_Plain(), 'nest');
     $expected->addChild(new T_Text_Paragraph('para1'))->addChild(new T_Text_Paragraph('para2'));
     $expected->nest->addChild(new T_Text_Paragraph('nested1'))->addChild(new T_Text_Paragraph('nested2'));
     $element = new T_Text_Plain("para1\n\n\npara2");
     $element->addChild(new T_Text_Plain("nested1\n\nnested2"), 'nest');
     $element->accept(new T_Text_ParagraphLexer());
     $this->assertEquals($expected, $element);
 }
Example #10
0
 /**
  * Returns original formatted text.
  *
  * @return string  original formatting
  */
 function __toString()
 {
     $delimiter = str_repeat('=', $this->level + 1);
     return $delimiter . ' ' . trim(parent::__toString()) . ' ' . $delimiter . EOL . EOL;
 }
Example #11
0
 /**
  * Returns original formatted text.
  *
  * @return string  original formatting
  */
 function __toString()
 {
     $content = parent::__toString();
     return '[' . $this->getUrl() . ' ' . $content . ']';
 }
Example #12
0
    function testParsesARepeatedlyNestedList()
    {
        $type1 = T_Text_List::ORDERED;
        $type2 = T_Text_List::UNORDERED;
        $content = <<<CONTENT
          {$type1} Item #1
            {$type2} Item #2
            {$type2} Item #3
          {$type1} Item #4
          {$type1} Item #5
            {$type2} Item #6
            {$type2} Item #7
          {$type1} Item #8
CONTENT;
        $text = new T_Text_Plain($content);
        $expect = new T_Text_Plain();
        $expect->addChild($list = new T_Text_List($type1));
        $list->addChild($item = new T_Text_ListItem('Item #1'));
        $item->addChild($nest = new T_Text_List($type2));
        $nest->addChild(new T_Text_ListItem('Item #2'));
        $nest->addChild(new T_Text_ListItem('Item #3'));
        $list->addChild(new T_Text_ListItem('Item #4'));
        $list->addChild($item2 = new T_Text_ListItem('Item #5'));
        $item2->addChild($nest2 = new T_Text_List($type2));
        $nest2->addChild(new T_Text_ListItem('Item #6'));
        $nest2->addChild(new T_Text_ListItem('Item #7'));
        $list->addChild(new T_Text_ListItem('Item #8'));
        $text->accept(new T_Text_ListLexer());
        $this->assertEquals($expect, $text);
    }
Example #13
0
 function testWindowsLineFeedIsRecognised()
 {
     $element = new T_Text_Plain('pre' . "\r\n" . '== header ==' . "\r\n" . 'post');
     $element->accept(new T_Text_HeaderLexer());
     $expected = new T_Text_Plain();
     $expected->addChild(new T_Text_Plain('pre'));
     $expected->addChild(new T_Text_Header(1, 'header'));
     $expected->addChild(new T_Text_Plain('post'));
     $this->assertEquals($expected, $element);
 }
Example #14
0
 function testParsesMultipleTablesInOneBlockWithPriorAndPostContent()
 {
     $text = new T_Text_Plain("Iñtërnât\n| lizætiøn | Iñtër |\niônàl\n| ætiøn | Iñt |\nizætiøn");
     $expect = new T_Text_Plain();
     $expect->addChild(new T_Text_Plain('Iñtërnât'));
     $expect->addChild($table = new T_Text_Table());
     $table->addChild($row = new T_Text_TableRow());
     $row->addChild(new T_Text_TableCell('lizætiøn'))->addChild(new T_Text_TableCell('Iñtër'));
     $expect->addChild(new T_Text_Plain('iônàl'));
     $expect->addChild($table = new T_Text_Table());
     $table->addChild($row = new T_Text_TableRow());
     $row->addChild(new T_Text_TableCell('ætiøn'))->addChild(new T_Text_TableCell('Iñt'));
     $expect->addChild(new T_Text_Plain('izætiøn'));
     $text->accept(new T_Text_TableLexer());
     $this->assertEquals($expect, $text);
 }
Example #15
0
 function testEmphTextParsedInChildElement()
 {
     $expected = new T_Text_Plain('parent');
     $expected->addChild(new T_Text_Plain(), 'nest');
     $expected->nest->addChild(new T_Text_Emph('content'));
     $element = new T_Text_Plain('parent');
     $element->addChild(new T_Text_Plain('**content**'), 'nest');
     $element->accept(new T_Text_EmphLexer());
     $this->assertEquals($expected, $element);
 }
Example #16
0
 /**
  * Create table cell.
  *
  * @param string $content  content
  * @param int $type
  */
 function __construct($content, $type = self::PLAIN, $span = 1)
 {
     $this->type = $type;
     $this->span = $span;
     parent::__construct($content);
 }
Example #17
0
 function testCanRenderMultipleInternalLinks()
 {
     $wiki = new T_Text_Plain('parent');
     $wiki->addChild(new T_Text_InternalLink('content1', '/url1'));
     $wiki->addChild(new T_Text_InternalLink('content2', '/url2'));
     $url1 = $this->getRootUrl()->__toString() . '/url1';
     $url2 = $this->getRootUrl()->__toString() . '/url2';
     $expect = 'parent' . '<a href="' . $url1 . '">content1</a>' . '<a href="' . $url2 . '">content2</a>';
     $this->assertSame($expect, $this->getVisitorRender($wiki));
 }