Skip to content

Commit 4b60dd9

Browse files
Loris CroLoris Cro
authored andcommitted
fmt: fix regression when formatting pre contents
closes #111
1 parent b8a6302 commit 4b60dd9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/html/Ast.zig

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,11 @@ pub fn render(ast: Ast, src: []const u8, w: *Writer) !void {
11321132
const txt = current.open.slice(src);
11331133
const parent_kind = ast.nodes[current.parent_idx].kind;
11341134
switch (parent_kind) {
1135-
else => {
1135+
else => blk: {
1136+
if (pre > 0) {
1137+
try w.writeAll(txt);
1138+
break :blk;
1139+
}
11361140
var it = std.mem.splitScalar(u8, txt, '\n');
11371141
var first = true;
11381142
var empty_line = false;
@@ -2069,6 +2073,28 @@ test "respect empty lines" {
20692073
try std.testing.expectFmt(expected, "{f}", .{ast.formatter(case)});
20702074
}
20712075

2076+
test "pre formatting" {
2077+
const case = comptime std.fmt.comptimePrint(
2078+
\\<!DOCTYPE html>
2079+
\\<html>
2080+
\\{0c}<head>
2081+
\\{0c}{0c}<title>Test</title>
2082+
\\{0c}</head>
2083+
\\{0c}<body>
2084+
\\{0c}{0c}<pre>Line 1
2085+
\\Line 2
2086+
\\Line 3
2087+
\\</pre>
2088+
\\{0c}</body>
2089+
\\</html>
2090+
\\
2091+
, .{'\t'});
2092+
2093+
const ast = try Ast.init(std.testing.allocator, case, .html, false);
2094+
defer ast.deinit(std.testing.allocator);
2095+
try std.testing.expectFmt(case, "{f}", .{ast.formatter(case)});
2096+
}
2097+
20722098
pub const Cursor = struct {
20732099
ast: Ast,
20742100
idx: u32,

0 commit comments

Comments
 (0)