Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ where
self.text(s)
}

fn multiline_string(&'a self, s: &str) -> DocBuilder<'a, Self, A> {
let delimiter = "%".repeat(min_interpolate_sign(s));
self.hardline()
.append(self.intersperse(s.lines().map(|d| self.text(d.to_owned())), self.hardline()))
.enclose(format!("m{delimiter}\""), format!("\"{delimiter}"))
}

fn metadata(&'a self, mv: &MetaValue, with_doc: bool) -> DocBuilder<'a, Self, A> {
if let Some(types) = &mv.types {
self.text(":")
Expand All @@ -71,20 +78,19 @@ where
}
.append(if with_doc {
mv.doc
.clone()
.as_ref()
.map(|doc| {
self.text("|")
.append(self.space())
.append(self.text("doc"))
.append(self.space())
.append(
self.hardline()
.append(self.intersperse(
doc.lines().map(|d| self.escaped_string(d)),
self.hardline().clone(),
))
.double_quotes(),
)
.append(self.hardline())
.append({
if doc.contains('\n') {
self.multiline_string(doc)
} else {
self.escaped_string(doc).double_quotes()
}
})
.append(self.line())
})
.unwrap_or_else(|| self.nil())
Expand Down
17 changes: 17 additions & 0 deletions tests/snapshot/inputs/pretty/multiline_doc.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
field | doc m%%"
Contract to enforce the value is a string that represents a boolean literal. Additionally casts "True" to "true"
and "False" to "false". This shouldn't interpolate: %{null}

For example:
```nickel
("True" | BoolLiteral) =>
"true"
("hello" | BoolLiteral) =>
error
(true | BoolLiteral) =>
error
```
"%%
= 1
}
21 changes: 21 additions & 0 deletions tests/snapshot/snapshots/snapshot__pretty_multiline_doc.ncl.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: tests/snapshot/main.rs
expression: snapshot
---
{
field | doc
m%%"
Contract to enforce the value is a string that represents a boolean literal. Additionally casts "True" to "true"
and "False" to "false". This shouldn't interpolate: %{null}

For example:
```nickel
("True" | BoolLiteral) =>
"true"
("hello" | BoolLiteral) =>
error
(true | BoolLiteral) =>
error
```"%%
= 1,
}