Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
vendor/
report/
composer.lock
Expand Down
15 changes: 9 additions & 6 deletions src/Indenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ public function indent ($input) {
$input = preg_replace('/\s{2,}/', ' ', $input);

// Remove inline elements and replace them with text entities.
if (preg_match_all('/<(' . implode('|', $this->inline_elements) . ')[^>]*>(?:[^<]*)<\/\1>/', $input, $matches)) {
$this->temporary_replacements_inline = $matches[0];
$inlineElementsCounter = 0;
while (preg_match_all('/<(' . implode('|', $this->inline_elements) . ')[^>]*>(?:[^<]*)<\/\1>/', $input, $matches)) {
foreach ($matches[0] as $i => $match) {
$input = str_replace($match, 'ᐃ' . ($i + 1) . 'ᐃ', $input);
$this->temporary_replacements_inline[$inlineElementsCounter] = $match;
$inlineElementsCounter++;
$input = str_replace($match, 'ᐃ' . $inlineElementsCounter . 'ᐃ', $input);
}
}

Expand All @@ -93,7 +95,7 @@ public function indent ($input) {

$patterns = array(
// block tag
'/^(<([a-z]+)(?:[^>]*)>(?:[^<]*)<\/(?:\2)>)/' => static::MATCH_INDENT_NO,
'/^(<([a-z|h1-6]+)(?:[^>]*)>(?:[^<]*)<\/(?:\2)>)/' => static::MATCH_INDENT_NO,
// DOCTYPE
'/^<!([^>]*)>/' => static::MATCH_INDENT_NO,
// tag with implied closing
Expand Down Expand Up @@ -161,8 +163,9 @@ public function indent ($input) {
$output = str_replace('<script>' . ($i + 1) . '</script>', $original, $output);
}

foreach ($this->temporary_replacements_inline as $i => $original) {
$output = str_replace('ᐃ' . ($i + 1) . 'ᐃ', $original, $output);
for($i = $inlineElementsCounter; $i > 0; $i--)
{
$output = str_replace('ᐃ' . $i . 'ᐃ', $this->temporary_replacements_inline[$i-1], $output);
}

return trim($output);
Expand Down
2 changes: 1 addition & 1 deletion tests/IndenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function logProvider () {
'<p></p>',
array(
'rule' => 'NO',
'pattern' => '/^(<([a-z]+)(?:[^>]*)>(?:[^<]*)<\\/(?:\\2)>)/',
'pattern' => '/^(<([a-z|h1-6]+)(?:[^>]*)>(?:[^<]*)<\/(?:\2)>)/',
'subject' => '<p></p>',
'match' => '<p></p>',
)
Expand Down
1 change: 1 addition & 0 deletions tests/sample/input/9999-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</script>
<div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div><strong><a href="#">Test link</a></strong></div>
<div><table border="1" style="background-color: red;"><tr><td>A cell test!</td>
<td colspan="2" rowspan="2"><table border="1" style="background-color: green;"><tr> <td>Cell</td><td colspan="2" rowspan="2"></td></tr><tr>
<td><input><input><input></td></tr><tr><td>Cell</td><td>Cell</td><td>Ce
Expand Down
1 change: 1 addition & 0 deletions tests/sample/output/9999-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</script>
<div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div><strong><a href="#">Test link</a></strong></div>
<div>
<table border="1" style="background-color: red;">
<tr>
Expand Down