Index: pkg/dart_messages/bin/publish.dart |
diff --git a/pkg/dart_messages/bin/publish.dart b/pkg/dart_messages/bin/publish.dart |
index 4b497b8113323e9908a9146240217e04e536399c..acba54f4371238ab979f35e7d29eb5eeb1fe2922 100644 |
--- a/pkg/dart_messages/bin/publish.dart |
+++ b/pkg/dart_messages/bin/publish.dart |
@@ -112,17 +112,25 @@ void emitDart2js() { |
} |
if (message.examples != null) { |
out.writeln(",\n examples: const ["); |
+ |
+ String escapeExampleContent(String content) { |
+ if (content.contains("\n") || content.contains('"')) { |
+ return 'r"""\n$content"""'; |
+ } else if (content.contains("\\")) { |
+ return 'r"$content"'; |
+ } |
+ return '"$content"'; |
+ } |
for (var example in message.examples) { |
if (example is String) { |
- out.writeln(" r'''"); |
- out.write(example); |
- out.write("'''"); |
+ out.write(" "); |
+ out.write(escapeExampleContent(example)); |
} else if (example is Map) { |
out.writeln(" const {"); |
example.forEach((String fileName, String content) { |
- out.writeln(" '$fileName': r'''"); |
- out.write(content); |
- out.writeln("''',"); |
+ out.writeln(" '$fileName': "); |
+ out.write(escapeExampleContent(content)); |
+ out.writeln(","); |
}); |
out.write(" }"); |
} |