diff --git a/.gitignore b/.gitignore index 5263cf6..c2d332d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ vendor/ report/ composer.lock diff --git a/src/Indenter.php b/src/Indenter.php index 3dfa08c..cefa2f1 100644 --- a/src/Indenter.php +++ b/src/Indenter.php @@ -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); } } @@ -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 @@ -161,8 +163,9 @@ public function indent ($input) { $output = str_replace('', $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); diff --git a/tests/IndenterTest.php b/tests/IndenterTest.php index e439c10..f64f16b 100644 --- a/tests/IndenterTest.php +++ b/tests/IndenterTest.php @@ -52,7 +52,7 @@ public function logProvider () { '

', array( 'rule' => 'NO', - 'pattern' => '/^(<([a-z]+)(?:[^>]*)>(?:[^<]*)<\\/(?:\\2)>)/', + 'pattern' => '/^(<([a-z|h1-6]+)(?:[^>]*)>(?:[^<]*)<\/(?:\2)>)/', 'subject' => '

', 'match' => '

', ) diff --git a/tests/sample/input/9999-test.html b/tests/sample/input/9999-test.html index ba08057..8126fdc 100644 --- a/tests/sample/input/9999-test.html +++ b/tests/sample/input/9999-test.html @@ -10,6 +10,7 @@
+
Test link
A cell test!
Cell
CellCellCe diff --git a/tests/sample/output/9999-test.html b/tests/sample/output/9999-test.html index 70caf1f..62731d0 100644 --- a/tests/sample/output/9999-test.html +++ b/tests/sample/output/9999-test.html @@ -10,6 +10,7 @@