fix(cli): escape delimiters '"' and '`' in cst node text

This commit is contained in:
Will Lillis 2025-08-10 16:26:55 -04:00
parent 3294b04436
commit 3a47bc4435

View file

@ -735,6 +735,14 @@ const fn escape_invisible(c: char) -> Option<&'static str> {
})
}
const fn escape_delimiter(c: char) -> Option<&'static str> {
Some(match c {
'`' => "\\`",
'\"' => "\\\"",
_ => return None,
})
}
pub fn render_cst<'a, 'b: 'a>(
source_code: &[u8],
tree: &'b Tree,
@ -796,6 +804,8 @@ fn render_node_text(source: &str) -> String {
.fold(String::with_capacity(source.len()), |mut acc, c| {
if let Some(esc) = escape_invisible(c) {
acc.push_str(esc);
} else if let Some(esc) = escape_delimiter(c) {
acc.push_str(esc);
} else {
acc.push(c);
}