Skip to content

Commit 8fa9ec3

Browse files
Add new use_html5 API in Term
1 parent 90425dd commit 8fa9ec3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

crates/anstyle-svg/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct Term {
4141
font_family: &'static str,
4242
min_width_px: usize,
4343
padding_px: usize,
44+
use_html5: bool,
4445
}
4546

4647
impl Term {
@@ -54,6 +55,7 @@ impl Term {
5455
font_family: "SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace",
5556
min_width_px: 720,
5657
padding_px: 10,
58+
use_html5: true,
5759
}
5860
}
5961

@@ -87,6 +89,12 @@ impl Term {
8789
self
8890
}
8991

92+
/// Whether or not to generate HTML5 compatible tags. Enabled by default.
93+
pub const fn use_html5(mut self, use_html5: bool) -> Self {
94+
self.use_html5 = use_html5;
95+
self
96+
}
97+
9098
/// Render the SVG with the terminal defined
9199
///
92100
/// **Note:** Lines are not wrapped. This is intentional as this attempts to convey the exact
@@ -296,6 +304,7 @@ impl Term {
296304
fn render_content(&self, buffer: &mut String, styled_lines: Vec<Vec<adapter::Element>>) {
297305
use std::fmt::Write as _;
298306

307+
let br = if self.use_html5 { "<br>" } else { "<br />" };
299308
writeln!(buffer, r#" <div class="container {FG}">"#).unwrap();
300309
for line in &styled_lines {
301310
if line.iter().any(|e| e.style.get_bg_color().is_some()) {
@@ -305,7 +314,7 @@ impl Term {
305314
}
306315
write_bg_span(buffer, "span", &element.style, &element.text);
307316
}
308-
writeln!(buffer, r#"<br />"#).unwrap();
317+
buffer.write_str(br).unwrap();
309318
}
310319

311320
for element in line {
@@ -314,7 +323,7 @@ impl Term {
314323
}
315324
write_fg_span(buffer, "span", element, &element.text);
316325
}
317-
writeln!(buffer, r#"<br />"#).unwrap();
326+
buffer.write_str(br).unwrap();
318327
}
319328
writeln!(buffer, r#" </div>"#).unwrap();
320329
}

0 commit comments

Comments
 (0)