Changeset View
Changeset View
Standalone View
Standalone View
src/parser/html/PhutilDOMNode.php
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function setRawHead($raw_string) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setRawTail($raw_tail) { | public function setRawTail($raw_tail) { | ||||
$this->rawTail = $raw_tail; | $this->rawTail = $raw_tail; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getRawString() { | public function newRawString() { | ||||
$raw = array(); | $raw = array(); | ||||
$raw[] = $this->rawHead; | $raw[] = $this->rawHead; | ||||
foreach ($this->getChildren() as $child) { | foreach ($this->getChildren() as $child) { | ||||
$raw[] = $child->getRawString(); | $raw[] = $child->newRawString(); | ||||
} | } | ||||
$raw[] = $this->rawTail; | $raw[] = $this->rawTail; | ||||
return implode('', $raw); | return implode('', $raw); | ||||
} | } | ||||
public function toDictionary() { | public function toDictionary() { | ||||
Show All 37 Lines | foreach ($this->getChildren() as $child) { | ||||
if (isset($tag_map[$tag_name])) { | if (isset($tag_map[$tag_name])) { | ||||
$nodes[] = $child; | $nodes[] = $child; | ||||
continue; | continue; | ||||
} | } | ||||
// Otherwise, this is some other tag. Convert it into a content | // Otherwise, this is some other tag. Convert it into a content | ||||
// node. | // node. | ||||
$raw_string = $child->getRawString(); | $raw_string = $child->newRawString(); | ||||
$nodes[] = id(new self()) | $nodes[] = id(new self()) | ||||
->setContent($raw_string) | ->setContent($raw_string) | ||||
->setRawHead($raw_string); | ->setRawHead($raw_string); | ||||
} | } | ||||
return $this->mergeContentNodes($nodes); | return $this->mergeContentNodes($nodes); | ||||
} | } | ||||
public function getRawContentString() { | public function newRawContentString() { | ||||
$content_node = $this->selectChildrenWithTags(array()); | $content_node = $this->selectChildrenWithTags(array()); | ||||
if (!$content_node) { | if (!$content_node) { | ||||
return ''; | return ''; | ||||
} | } | ||||
return head($content_node)->getRawString(); | return head($content_node)->newRawString(); | ||||
} | } | ||||
public function mergeContent() { | public function mergeContent() { | ||||
$this->children = $this->mergeContentNodes($this->children); | $this->children = $this->mergeContentNodes($this->children); | ||||
foreach ($this->getChildren() as $child) { | foreach ($this->getChildren() as $child) { | ||||
$child->parentNode = $this; | $child->parentNode = $this; | ||||
$child->mergeContent(); | $child->mergeContent(); | ||||
Show All 31 Lines | foreach ($list as $item) { | ||||
} | } | ||||
if (!$item) { | if (!$item) { | ||||
continue; | continue; | ||||
} | } | ||||
$parts = array(); | $parts = array(); | ||||
foreach ($item as $content_node) { | foreach ($item as $content_node) { | ||||
$parts[] = $content_node->getRawString(); | $parts[] = $content_node->newRawString(); | ||||
} | } | ||||
$parts = implode('', $parts); | $parts = implode('', $parts); | ||||
if (!strlen($parts)) { | if (!strlen($parts)) { | ||||
continue; | continue; | ||||
} | } | ||||
$results[] = id(new self()) | $results[] = id(new self()) | ||||
->setContent($parts) | ->setContent($parts) | ||||
->setRawHead($parts); | ->setRawHead($parts); | ||||
} | } | ||||
return $results; | return $results; | ||||
} | } | ||||
} | } |