Skip to content

Commit 4d5340c

Browse files
committed
dont indent empty lines in raw
1 parent 730870a commit 4d5340c

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ use Sinnbeck\HtmlAst\Printer;
106106
echo Printer::make($nodes)->render(1);
107107
```
108108

109-
By default the output is indented with 4 spaces.
109+
By default, the output is indented with 4 spaces.
110110
This can be easily changed by calling `->withIndent()`
111111
```php
112112
use Sinnbeck\HtmlAst\Printer;

src/Printer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ protected function renderRaw(string $raw, int $level): string
145145
$line = ltrim($line);
146146
$first = false;
147147
}
148-
$newLines[] = $baseIndent . $line;
148+
$indent = $line ? $baseIndent : '';
149+
$newLines[] = $indent . $line;
149150
}
150151

151152
return implode($this->newline, $newLines) . $this->newline;

tests/fixtures/complex.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@
2222
<li>:phone:</li>
2323
</ul>
2424
</script>
25+
<script>
26+
var message = 'Hello World!';
27+
28+
alert(message);
29+
</script>
2530
</body>
2631
</html>

0 commit comments

Comments
 (0)