fix(cli): escape delimiters '"' and '`' in cst node text
This commit is contained in:
parent
3294b04436
commit
3a47bc4435
1 changed files with 10 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue