Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions crates/anstyle-svg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct Term {
font_family: &'static str,
min_width_px: usize,
padding_px: usize,
use_html5: bool,
}

impl Term {
Expand All @@ -54,6 +55,7 @@ impl Term {
font_family: "SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace",
min_width_px: 720,
padding_px: 10,
use_html5: true,
}
}

Expand Down Expand Up @@ -87,6 +89,12 @@ impl Term {
self
}

/// Whether or not to generate HTML5 compatible tags. Enabled by default.
pub const fn use_html5(mut self, use_html5: bool) -> Self {
self.use_html5 = use_html5;
self
}

/// Render the SVG with the terminal defined
///
/// **Note:** Lines are not wrapped. This is intentional as this attempts to convey the exact
Expand Down Expand Up @@ -296,6 +304,7 @@ impl Term {
fn render_content(&self, buffer: &mut String, styled_lines: Vec<Vec<adapter::Element>>) {
use std::fmt::Write as _;

let br = if self.use_html5 { "<br>" } else { "<br />" };
writeln!(buffer, r#" <div class="container {FG}">"#).unwrap();
for line in &styled_lines {
if line.iter().any(|e| e.style.get_bg_color().is_some()) {
Expand All @@ -305,7 +314,7 @@ impl Term {
}
write_bg_span(buffer, "span", &element.style, &element.text);
}
writeln!(buffer, r#"<br />"#).unwrap();
buffer.write_str(br).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore the use of writeln! as that is not relevant to this commit (overlooked it until I could see how the tests changed

}

for element in line {
Expand All @@ -314,7 +323,7 @@ impl Term {
}
write_fg_span(buffer, "span", element, &element.text);
}
writeln!(buffer, r#"<br />"#).unwrap();
buffer.write_str(br).unwrap();
}
writeln!(buffer, r#" </div>"#).unwrap();
}
Expand Down
Loading