diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 6ddf433c..58b6de34 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -2666,12 +2666,20 @@ fn node_is_visible(node: &Node) -> bool {
     node.is_missing() || (node.is_named() && node.language().node_kind_is_visible(node.kind_id()))
 }
 
+fn format_anonymous_node_kind(kind: &str) -> Cow<str> {
+    if kind.contains('"') {
+        Cow::Owned(kind.replace('"', "\\\""))
+    } else {
+        Cow::Borrowed(kind)
+    }
+}
+
 pub fn pretty_print_tree<W: fmt::Write>(fmt: &mut W, node: Node) -> fmt::Result {
     if node.child_count() == 0 {
         if node_is_visible(&node) {
             write!(fmt, "({})", node.kind())
         } else {
-            write!(fmt, "\"{}\"", node.kind())
+            write!(fmt, "\"{}\"", format_anonymous_node_kind(node.kind()))
         }
     } else {
         pretty_print_tree_impl(fmt, &mut node.walk(), 0)
@@ -2696,7 +2704,7 @@ fn pretty_print_tree_impl<W: fmt::Write>(
 
         write!(fmt, "({}", node.kind())?;
     } else {
-        write!(fmt, " \"{}\"", node.kind())?;
+        write!(fmt, " \"{}\"", format_anonymous_node_kind(node.kind()))?;
     }
 
     // Handle children.