Changeset View
Changeset View
Standalone View
Standalone View
src/parser/html/PhutilHTMLParser.php
| Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | foreach ($parts as $part) { | ||||
| // If this part is a tag, restore the angle brackets. | // If this part is a tag, restore the angle brackets. | ||||
| if ($part['tag']) { | if ($part['tag']) { | ||||
| $content = '<'.$content.'>'; | $content = '<'.$content.'>'; | ||||
| } | } | ||||
| $node = id(new PhutilDOMNode()) | $node = id(new PhutilDOMNode()) | ||||
| ->setContent($content) | ->setContent($content) | ||||
| ->setRawString($content); | ->setRawHead($content); | ||||
| $this->getCursor()->appendChild($node); | $this->getCursor()->appendChild($node); | ||||
| } | } | ||||
| $root->mergeContent(); | $root->mergeContent(); | ||||
| return $root; | return $root; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | private function newTagDOMNode(array $part) { | ||||
| // If we find a valid closing tag, try to find a matching tag on the stack. | // If we find a valid closing tag, try to find a matching tag on the stack. | ||||
| // If we find a matching tag, close it. | // If we find a matching tag, close it. | ||||
| // If we do not find a matching tag, treat the closing tag as content. | // If we do not find a matching tag, treat the closing tag as content. | ||||
| if ($is_close) { | if ($is_close) { | ||||
| $cursor = $this->getCursor(); | $cursor = $this->getCursor(); | ||||
| while ($cursor) { | while ($cursor) { | ||||
| if ($cursor->getTagName() === $tag_name) { | if ($cursor->getTagName() === $tag_name) { | ||||
| // Add this raw content to the raw content of the tag we're closing. | |||||
| $cursor->setRawTail('<'.$raw_content.'>'); | |||||
| $parent = $cursor->getParentNode(); | $parent = $cursor->getParentNode(); | ||||
| $this->setCursor($parent); | $this->setCursor($parent); | ||||
| return true; | return true; | ||||
| } | } | ||||
| $cursor = $cursor->getParentNode(); | $cursor = $cursor->getParentNode(); | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| if (strlen($attributes)) { | if (strlen($attributes)) { | ||||
| $attribute_map = $this->parseAttributes($attributes); | $attribute_map = $this->parseAttributes($attributes); | ||||
| // If the attributes can't be parsed, treat the tag as content. | // If the attributes can't be parsed, treat the tag as content. | ||||
| if ($attribute_map === null) { | if ($attribute_map === null) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| } else { | } else { | ||||
| $attribute_map = array(); | $attribute_map = array(); | ||||
| } | } | ||||
| $node = id(new PhutilDOMNode()) | $node = id(new PhutilDOMNode()) | ||||
| ->setTagName($tag_name) | ->setTagName($tag_name) | ||||
| ->setAttributes($attribute_map) | ->setAttributes($attribute_map) | ||||
| ->setRawString('<'.$raw_content.'>'); | ->setRawHead('<'.$raw_content.'>'); | ||||
| $cursor = $this->getCursor(); | $cursor = $this->getCursor(); | ||||
| $cursor->appendChild($node); | $cursor->appendChild($node); | ||||
| if (!$self_close) { | if (!$self_close) { | ||||
| $this->setCursor($node); | $this->setCursor($node); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 210 Lines • Show Last 20 Lines | |||||