예제 #1
0
 protected function finalizeOutput()
 {
     $this->outputText($this->textLen, 0, \true);
     do {
         $this->output = \preg_replace('(<([^ />]+)></\\1>)', '', $this->output, -1, $cnt);
     } while ($cnt > 0);
     if (\strpos($this->output, '</i><i>') !== \false) {
         $this->output = \str_replace('</i><i>', '', $this->output);
     }
     $this->output = Utils::encodeUnicodeSupplementaryCharacters($this->output);
     $tagName = $this->isRich ? 'r' : 't';
     $tmp = '<' . $tagName;
     foreach (\array_keys($this->namespaces) as $prefix) {
         $tmp .= ' xmlns:' . $prefix . '="urn:s9e:TextFormatter:' . $prefix . '"';
     }
     $this->output = $tmp . '>' . $this->output . '</' . $tagName . '>';
 }
예제 #2
0
 /**
  * @testdox encodeUnicodeSupplementaryCharacters() tests
  * @dataProvider getEncodeUnicodeSupplementaryCharactersTests
  */
 public function testEncodeUnicodeSupplementaryCharacters($original, $expected)
 {
     $this->assertSame($expected, Utils::encodeUnicodeSupplementaryCharacters($original));
 }
예제 #3
0
 /**
  * Finalize the output by appending the rest of the unprocessed text and create the root node
  *
  * @return void
  */
 protected function finalizeOutput()
 {
     // Output the rest of the text and close the last paragraph
     $this->outputText($this->textLen, 0, true);
     // Remove empty tag pairs, e.g. <I><U></U></I> as well as empty paragraphs
     do {
         $this->output = preg_replace('(<([^ />]+)></\\1>)', '', $this->output, -1, $cnt);
     } while ($cnt > 0);
     // Merge consecutive <i> tags
     if (strpos($this->output, '</i><i>') !== false) {
         $this->output = str_replace('</i><i>', '', $this->output);
     }
     // Encode Unicode characters that are outside of the BMP
     $this->output = Utils::encodeUnicodeSupplementaryCharacters($this->output);
     // Use a <r> root if the text is rich, or <t> for plain text (including <p></p> and <br/>)
     $tagName = $this->isRich ? 'r' : 't';
     // Prepare the root node with all the namespace declarations
     $tmp = '<' . $tagName;
     foreach (array_keys($this->namespaces) as $prefix) {
         $tmp .= ' xmlns:' . $prefix . '="urn:s9e:TextFormatter:' . $prefix . '"';
     }
     $this->output = $tmp . '>' . $this->output . '</' . $tagName . '>';
 }