From c6620c82b3d66c8a089751086d609122e513a390 Mon Sep 17 00:00:00 2001 From: Predrag Leka Date: Thu, 11 Feb 2016 14:11:26 +0100 Subject: [PATCH 1/3] * regex for block tags fixed to include h1-h6 --- .gitignore | 1 + src/Indenter.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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..395cad4 100644 --- a/src/Indenter.php +++ b/src/Indenter.php @@ -93,7 +93,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 From 8332e3d4e27c966fac94993bdf6c5a79cbeeb426 Mon Sep 17 00:00:00 2001 From: Predrag Leka Date: Wed, 2 Mar 2016 11:53:21 +0100 Subject: [PATCH 2/3] * regex in test fixed to reflect changes in Indenter class --- tests/IndenterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' => '

', ) From 35e7e747aeb5e215e3bfe9fc5a931a244afe3324 Mon Sep 17 00:00:00 2001 From: Predrag Leka Date: Wed, 9 Mar 2016 18:03:54 +0100 Subject: [PATCH 3/3] *Inline tags are now handled recursively. Earlier

text

would push tag into new line so output would look like this

text

now it stays in one line * Test row added into test HTML to check this case --- src/Indenter.php | 13 ++++++++----- tests/sample/input/9999-test.html | 1 + tests/sample/output/9999-test.html | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Indenter.php b/src/Indenter.php index 395cad4..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); } } @@ -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/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 @@
+
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 @@