MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / formatSummary

Function formatSummary

test/conductor/diff-utils.ts:84–115  ·  view source on GitHub ↗
(message: string, diffText: string|null, cutoff: number = SUMMARY_LENGTH_CUTOFF)

Source from the content-addressed store, hash-verified

82const SUMMARY_LENGTH_CUTOFF = 3950;
83
84export function formatSummary(message: string, diffText: string|null, cutoff: number = SUMMARY_LENGTH_CUTOFF): string {
85 let summary = message;
86 if (diffText) {
87 summary += '\n\n' + diffText;
88 }
89
90 const lines = summary.split('\n');
91 let result = '';
92 let currentLength = 13; // for <pre></pre> and some safety margin
93
94 for (const line of lines) {
95 const sanitized = sanitize(line);
96 let highlighted = sanitized;
97 if (line.startsWith('+')) {
98 highlighted = `<span style="color: green;">${sanitized}</span>`;
99 } else if (line.startsWith('-')) {
100 highlighted = `<span style="color: red;">${sanitized}</span>`;
101 }
102
103 if (currentLength + highlighted.length + 1 > cutoff) {
104 result += '\n... (truncated)';
105 break;
106 }
107 if (result.length > 0) {
108 result += '\n';
109 }
110 result += highlighted;
111 currentLength += highlighted.length + 1;
112 }
113
114 return `<pre>${result}</pre>`;
115}
116
117export function formatAsHtml(assertionDiff: any): string|null {
118 const diffText = formatDiffText(assertionDiff);

Callers 1

formatAsHtmlFunction · 0.85

Calls 2

sanitizeFunction · 0.85
splitMethod · 0.80

Tested by

no test coverage detected