Skip to content

Commit

Permalink
Adicionado exceções de tags que não precisam ser fechadas.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Gunther committed Apr 15, 2019
1 parent 859869b commit 9da3315
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/HtmlString.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

class HtmlString {

const TAGS_NAO_PRECISA_FECHAR = array(
'<br>',
'<img>',
'<textarea>',
'<cut>'
);

/**
* @var string
*/
Expand Down Expand Up @@ -226,6 +233,10 @@ private function isClosedTag($tag) {
* @return array
*/
private function isOpenedTag($tag) {
if(in_array($tag, self::TAGS_NAO_PRECISA_FECHAR)){
return [];
}

if(preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag,$tag_matchings)) {
return $tag_matchings;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/WordwrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,18 @@ public function testWordwrap5() {
$this->assertEquals([$string], $wordWrapArray);
}

public function testNaoFecharTagListadas(){
$tagBr = "<br>Teste Tag br";
$wordWrapArray = HtmlString::get($tagBr)->wordwrapArray(48,true);
self::assertEquals(['<br>Teste Tag br'], $wordWrapArray);

$tagBr = "<br>Teste Tag br com quebra de linha no texto";
$wordWrapArray = HtmlString::get($tagBr)->wordwrapArray(25,true);
self::assertEquals(['<br>Teste Tag br com quebra d', 'e linha no texto'], $wordWrapArray);

$tagTextArea = "<textarea>Teste Tag TextArea";
$wordWrapArray = HtmlString::get($tagTextArea)->wordwrapArray(48,true);
self::assertEquals(['<textarea>Teste Tag TextArea'], $wordWrapArray);
}

}

0 comments on commit 9da3315

Please sign in to comment.