private function parseTextNode(\DOMText $node, $context) { /*{{{*/ $text = ""; $raw = $context['raw']; $indent = $context['indent']; $suffix = $context['line_suffix']; $value = $raw ? $node->nodeValue : Text\Utf8::normalizeWhitespace($node->nodeValue); if ($context['bullet']) { // bullet has been set by the parent, // it means we are the first child node // We have to apply the bullet to the first line of text $prefix = $indent . $context['bullet']; if (empty($value)) { return $prefix . $suffix . "\n"; } $wordwrap = $this->wordwrap - mb_strlen($prefix, $this->charset); //$first_line = $raw ? array_shift($lines) : trim(array_shift($lines)); $first_linebreak = mb_strpos($value, "\n", 0, $this->charset); if (false === $first_linebreak) { // no line break, only one line $first_line = $value; } else { // ----- get the first line $first_line = mb_substr($value, 0, $first_linebreak, $this->charset); } // ----- wrap it $wrapped = Text\MultiByte::wordwrap($first_line, $wordwrap, "\n", true, $this->charset); // ----- now get the wrapped first line $wrapped_first_linebreak = mb_strpos($wrapped, "\n", 0, $this->charset); if (false === $wrapped_first_linebreak) { // only one wrapped line return $prefix . $wrapped . "\n"; } else { $wrapped_first_line = mb_substr($wrapped, 0, $wrapped_first_linebreak, $this->charset); // ----- write it $text .= $prefix . $wrapped_first_line . "\n"; // remove the wrapped first-line from original value $value = mb_substr($value, $wrapped_first_linebreak, mb_strlen($value, $this->charset), $this->charset); } } // Handle remaining lines $prefix = $indent . $context['line_prefix']; $wordwrap = $this->wordwrap - mb_strlen($prefix, $this->charset); $value = Text\MultiByte::wordwrap($value, $wordwrap, "\n", true, $this->charset); $value = $raw ? $value : Text\Utf8::normalizeWhitespace($value); $lines = explode("\n", $value); foreach ($lines as $line) { $v = $raw ? $line : trim($line); if ($v) { $text .= $prefix . $v . "\n"; } } return $text; }
public function format() { return Text\MultiByte::wordwrap($this->xslt->transformToXml($this->dom), $this->wordwrap, "\n", true, $this->charset); }