');
73 | final contentWithNewlines = node['content'].replaceAll('\n', ' ');
74 |
75 | if (node['role'] == 'assistant') {
76 | try {
77 | final contentJson = jsonDecode(node['content']);
78 | final formattedJson = JsonEncoder.withIndent(' ')
79 | .convert(contentJson)
80 | .replaceAll('\n', ' ');
81 | final updatedJson = formattedJson.splitMapJoin(
82 | RegExp(r'(".+": ")([^"]+)(",?)'),
83 | onMatch: (match) {
84 | final key = match.group(1);
85 | final value = match.group(2);
86 | final comma = match.group(3);
87 | final formattedValue = value!.length > 80
88 | ? value.replaceAllMapped(
89 | RegExp(r'.{1,80}'), (match) => '${match.group(0)} ')
90 | : value;
91 | return '$key$formattedValue$comma';
92 | },
93 | onNonMatch: (nonMatch) => nonMatch,
94 | );
95 |
96 | htmlBuffer.write('$updatedJson ');
97 | } catch (e) {
98 | htmlBuffer.write('$contentWithNewlines');
99 | }
100 | } else {
101 | htmlBuffer.write('$contentWithNewlines');
102 | }
103 |
104 | htmlBuffer.write(' |