Skip to content

Commit

Permalink
update content_reg
Browse files Browse the repository at this point in the history
  • Loading branch information
faitheir committed Apr 28, 2020
1 parent eb245de commit 32bdd67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/DomParser/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private function __clone(){}
'start_tag_reg' => '/^\s*<([^>\s\/!]+)/is',
'start_end_tag_reg' => '/(^\s*>)|(^\s*\/>)/is',
'end_tag_reg' => '/^\s*<([^>\s\/]+)/is',
'content_reg' => '/^\s*([^<]+)|(<!--.*-->)/is',
'content_reg' => '/^\s*([^<]+)|(^\s*<!--((?!-->).)*-->)/is',
'attrs_reg' => '/^\s*([^=>< ]+)="([^"]*)"|\s([^=><\s]+)(?=\s|>)/iU',
# inverse parse
'tag_indent' => ' ',
Expand Down
9 changes: 5 additions & 4 deletions src/DomParser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private function _parseStartTag($domString, $parent)
$startTagMatch = [];
preg_match($this->_startTagReg, $domString, $startTagMatch);
$startTagName = $startTagMatch[1] ?? '';

if (empty($startTagName))
return [$domString, null];

Expand Down Expand Up @@ -131,13 +132,12 @@ private function _parseStartEndTag(& $domString, $node)
* @param $parent
* @return bool|string
*/
private function _parseEndTag($domString, $parent)
private function _parseEndTag($domString, $node)
{
if(empty($parent->nodeName))
if(empty($node->nodeName))
return $domString;

$endTagMatch = [];
if (preg_match('/^\s*(<\/' . $parent->nodeName . '>)/is', $domString, $endTagMatch)) {
if (preg_match('/^\s*(<\/' . $node->nodeName . '>)/is', $domString, $endTagMatch)) {
$endTagPos = strpos($domString, $endTagMatch[0]);
$domString = substr($domString, $endTagPos + strlen($endTagMatch[0]));
}
Expand Down Expand Up @@ -187,6 +187,7 @@ private function _parseAttrs($domString, $node)
*/
private function _parseContent($domString, $parent)
{

# match content
$contentMatch = [];
$match = preg_match($this->_contentReg, $domString, $contentMatch);
Expand Down
7 changes: 5 additions & 2 deletions tests/DomParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
</template>
HTML;

//echo '<pre>';
$dom = $parser->setConfig([
])->parse($html);

print_r($dom);
echo '<pre>';
print_r($dom);

$string = (string) $dom;
file_put_contents('test.vue', $string);

0 comments on commit 32bdd67

Please sign in to comment.