@@ -750,7 +750,10 @@ pub fn render(ast: Ast, src: []const u8, w: *Writer) !void {
750750 std .debug .assert (current .kind != .text );
751751 std .debug .assert (current .kind != .element_void );
752752 std .debug .assert (current .kind != .element_self_closing );
753- if (current .kind == .root ) return ;
753+ if (current .kind == .root ) {
754+ try w .writeAll ("\n " );
755+ return ;
756+ }
754757
755758 log .debug ("rendering exit ({}): {s} {any}" , .{
756759 indentation ,
@@ -1109,7 +1112,7 @@ fn debugNodes(nodes: []const Node, src: []const u8) void {
11091112}
11101113
11111114test "basics" {
1112- const case = "<html><head></head><body><div><link></div></body></html>" ;
1115+ const case = "<html><head></head><body><div><link></div></body></html>\n " ;
11131116
11141117 const ast = try Ast .init (std .testing .allocator , case , .html );
11151118 defer ast .deinit (std .testing .allocator );
@@ -1120,7 +1123,7 @@ test "basics" {
11201123test "basics - attributes" {
11211124 const case = "<html><head></head><body>" ++
11221125 \\<div id="foo" class="bar">
1123- ++ "<link></div></body></html>" ;
1126+ ++ "<link></div></body></html>\n " ;
11241127
11251128 const ast = try Ast .init (std .testing .allocator , case , .html );
11261129 defer ast .deinit (std .testing .allocator );
@@ -1137,6 +1140,7 @@ test "newlines" {
11371140 \\ <div><link></div>
11381141 \\ </body>
11391142 \\</html>
1143+ \\
11401144 ;
11411145 const ast = try Ast .init (std .testing .allocator , case , .html );
11421146 defer ast .deinit (std .testing .allocator );
@@ -1175,6 +1179,7 @@ test "formatting - simple" {
11751179 \\ <div><link></div>
11761180 \\ </body>
11771181 \\</html>
1182+ \\
11781183 ;
11791184 const ast = try Ast .init (std .testing .allocator , case , .html );
11801185 defer ast .deinit (std .testing .allocator );
@@ -1192,7 +1197,7 @@ test "formatting - attributes" {
11921197 \\ ></div>
11931198 \\ </div>
11941199 \\ </body>
1195- \\</html>
1200+ \\</html>
11961201 ;
11971202 const expected =
11981203 \\<html>
@@ -1207,6 +1212,7 @@ test "formatting - attributes" {
12071212 \\ </div>
12081213 \\ </body>
12091214 \\</html>
1215+ \\
12101216 ;
12111217 const ast = try Ast .init (std .testing .allocator , case , .html );
12121218 defer ast .deinit (std .testing .allocator );
@@ -1223,6 +1229,7 @@ test "pre" {
12231229 \\<b>
12241230 \\</b>
12251231 \\<pre> </pre>
1232+ \\
12261233 ;
12271234
12281235 const ast = try Ast .init (std .testing .allocator , case , .html );
@@ -1241,6 +1248,7 @@ test "pre text" {
12411248 \\ banana
12421249 \\</b>
12431250 \\<pre> banana </pre>
1251+ \\
12441252 ;
12451253
12461254 const ast = try Ast .init (std .testing .allocator , case , .html );
@@ -1277,6 +1285,7 @@ test "what" {
12771285 \\ </body>
12781286 \\</html>
12791287 \\<a href="#">foo</a>
1288+ \\
12801289 ;
12811290
12821291 const ast = try Ast .init (std .testing .allocator , case , .html );
@@ -1313,6 +1322,7 @@ test "spans" {
13131322 \\ <span>World</span>
13141323 \\ </body>
13151324 \\</html>
1325+ \\
13161326 ;
13171327
13181328 const ast = try Ast .init (std .testing .allocator , case , .html );
@@ -1327,6 +1337,7 @@ test "arrow span" {
13271337 const expected =
13281338 \\<a href="$if.permalink()">←
13291339 \\ <span var="$if.title"></span></a>
1340+ \\
13301341 ;
13311342
13321343 const ast = try Ast .init (std .testing .allocator , case , .html );
@@ -1343,7 +1354,7 @@ test "self-closing tag complex example" {
13431354 \\<svg viewBox="0 0 24 24">
13441355 \\<path d="M14.4,6H20V16H13L12.6,14H7V21H5V4H14L14.4,6M14,14H16V12H18V10H16V8H14V10L13,8V6H11V8H9V6H7V8H9V10H7V12H9V10H11V12H13V10L14,12V14M11,10V8H13V10H11M14,10H16V12H14V10Z" />
13451356 \\</svg>
1346- \\</div>
1357+ \\</div>
13471358 ;
13481359 const expected =
13491360 \\extend template="base.html"/>
@@ -1352,6 +1363,7 @@ test "self-closing tag complex example" {
13521363 \\ <path d="M14.4,6H20V16H13L12.6,14H7V21H5V4H14L14.4,6M14,14H16V12H18V10H16V8H14V10L13,8V6H11V8H9V6H7V8H9V10H7V12H9V10H11V12H13V10L14,12V14M11,10V8H13V10H11M14,10H16V12H14V10Z"/>
13531364 \\ </svg>
13541365 \\</div>
1366+ \\
13551367 ;
13561368 const ast = try Ast .init (std .testing .allocator , case , .html );
13571369 defer ast .deinit (std .testing .allocator );
0 commit comments