help: hack in support for preformatted lines

This works, but there are probably interesting edge cases around how it
works when directly adjacent to other paragraphs. I will have to think
about it a bit. This wrapping code in general would benefit from term
queries.

Perhaps violating the principle of least astonishment quite severely is
the fact that "> a" and ">" are detected as preformatted, but ">a" is
normal wrapped text. Supporting both ">a" and "> a" leads to
nonobvious whitespace behavior, but this code should not be able to
runtime error outside of the writer dying. This may be reevaluated in
the future, but I will leave it as-is for now.
This commit is contained in:
torque 2023-11-08 22:52:28 -08:00
parent 35915191fb
commit 768a81e2bd
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -65,6 +65,17 @@ pub fn StructuredPrinter(comptime Writer: type) type {
// we have a trailing line that needs to be cleaned up // we have a trailing line that needs to be cleaned up
if (location > indent) if (location > indent)
_ = try self.clearLine(indent); _ = try self.clearLine(indent);
location = try self.clearLine(indent);
continue;
}
if (line[0] == '>') maybe: {
if (line.len > 1) {
if (line[1] == ' ') {
try self.writer.writeAll(line[2..]);
} else break :maybe;
}
location = try self.clearLine(indent); location = try self.clearLine(indent);
continue; continue;
} }
@ -101,6 +112,7 @@ pub fn StructuredPrinter(comptime Writer: type) type {
} }
if (location > indent) if (location > indent)
try self.writer.writeByte(' '); try self.writer.writeByte(' ');
try self.writer.writeAll(choppee[0..split]); try self.writer.writeAll(choppee[0..split]);
location = try self.clearLine(indent); location = try self.clearLine(indent);
choppee = choppee[split + 1 ..]; choppee = choppee[split + 1 ..];