Skip to content

Commit 32bdd67

Browse files
committed
update content_reg
1 parent eb245de commit 32bdd67

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/DomParser/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private function __clone(){}
1313
'start_tag_reg' => '/^\s*<([^>\s\/!]+)/is',
1414
'start_end_tag_reg' => '/(^\s*>)|(^\s*\/>)/is',
1515
'end_tag_reg' => '/^\s*<([^>\s\/]+)/is',
16-
'content_reg' => '/^\s*([^<]+)|(<!--.*-->)/is',
16+
'content_reg' => '/^\s*([^<]+)|(^\s*<!--((?!-->).)*-->)/is',
1717
'attrs_reg' => '/^\s*([^=>< ]+)="([^"]*)"|\s([^=><\s]+)(?=\s|>)/iU',
1818
# inverse parse
1919
'tag_indent' => ' ',

src/DomParser/Parser.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private function _parseStartTag($domString, $parent)
8181
$startTagMatch = [];
8282
preg_match($this->_startTagReg, $domString, $startTagMatch);
8383
$startTagName = $startTagMatch[1] ?? '';
84+
8485
if (empty($startTagName))
8586
return [$domString, null];
8687

@@ -131,13 +132,12 @@ private function _parseStartEndTag(& $domString, $node)
131132
* @param $parent
132133
* @return bool|string
133134
*/
134-
private function _parseEndTag($domString, $parent)
135+
private function _parseEndTag($domString, $node)
135136
{
136-
if(empty($parent->nodeName))
137+
if(empty($node->nodeName))
137138
return $domString;
138-
139139
$endTagMatch = [];
140-
if (preg_match('/^\s*(<\/' . $parent->nodeName . '>)/is', $domString, $endTagMatch)) {
140+
if (preg_match('/^\s*(<\/' . $node->nodeName . '>)/is', $domString, $endTagMatch)) {
141141
$endTagPos = strpos($domString, $endTagMatch[0]);
142142
$domString = substr($domString, $endTagPos + strlen($endTagMatch[0]));
143143
}
@@ -187,6 +187,7 @@ private function _parseAttrs($domString, $node)
187187
*/
188188
private function _parseContent($domString, $parent)
189189
{
190+
190191
# match content
191192
$contentMatch = [];
192193
$match = preg_match($this->_contentReg, $domString, $contentMatch);

tests/DomParserTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
</template>
2929
HTML;
3030

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

35-
print_r($dom);
34+
echo '<pre>';
35+
print_r($dom);
36+
37+
$string = (string) $dom;
38+
file_put_contents('test.vue', $string);

0 commit comments

Comments
 (0)