Skip to content

Commit a9a05ad

Browse files
committed
fix(utils): handle descriptions ending in code block in report.md
1 parent 78388e6 commit a9a05ad

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/utils/src/lib/__snapshots__/report-to-md.spec.ts.snap

+5-5
Original file line numberDiff line numberDiff line change
@@ -393,31 +393,31 @@ ESLint rule **require-render-return**, from _react_ plugin. [📖 Docs](https://
393393
394394
🟨 <b>1.2 s</b> (score: 76)
395395
396-
[📖 Docs](https://developer.chrome.com/docs/lighthouse/performance/first-contentful-paint/)
396+
[📖 Docs](https://developer.chrome.com/docs/lighthouse/performance/first-contentful-paint/)
397397
398398
### Largest Contentful Paint (Lighthouse)
399399
400400
🟨 <b>1.5 s</b> (score: 81)
401401
402-
[📖 Docs](https://developer.chrome.com/docs/lighthouse/performance/largest-contentful-paint/)
402+
[📖 Docs](https://developer.chrome.com/docs/lighthouse/performance/largest-contentful-paint/)
403403
404404
### Total Blocking Time (Lighthouse)
405405
406406
🟩 <b>0 ms</b> (score: 100)
407407
408-
[📖 Docs](https://developer.chrome.com/docs/lighthouse/performance/lighthouse-total-blocking-time/)
408+
[📖 Docs](https://developer.chrome.com/docs/lighthouse/performance/lighthouse-total-blocking-time/)
409409
410410
### Cumulative Layout Shift (Lighthouse)
411411
412412
🟩 <b>0</b> (score: 100)
413413
414-
[📖 Docs](https://web.dev/cls/)
414+
[📖 Docs](https://web.dev/cls/)
415415
416416
### Speed Index (Lighthouse)
417417
418418
🟩 <b>1.2 s</b> (score: 93)
419419
420-
[📖 Docs](https://developer.chrome.com/docs/lighthouse/performance/speed-index/)
420+
[📖 Docs](https://developer.chrome.com/docs/lighthouse/performance/speed-index/)
421421
422422
423423

packages/utils/src/lib/report-to-md.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,21 @@ function getDocsAndDescription({
304304
docsUrl,
305305
description,
306306
}: AuditReport | CategoryConfig): string {
307-
return docsUrl
308-
? `${description || ''} ${link(docsUrl, '📖 Docs')}` + NEW_LINE + NEW_LINE
309-
: '';
307+
if (docsUrl) {
308+
const docsLink = link(docsUrl, '📖 Docs');
309+
if (!description) {
310+
return docsLink + NEW_LINE + NEW_LINE;
311+
}
312+
if (description.endsWith('```')) {
313+
// when description ends in code block, link must be moved to next paragraph
314+
return description + NEW_LINE + NEW_LINE + docsLink + NEW_LINE + NEW_LINE;
315+
}
316+
return `${description} ${docsLink}${NEW_LINE}${NEW_LINE}`;
317+
}
318+
if (description) {
319+
return description + NEW_LINE + NEW_LINE;
320+
}
321+
return '';
310322
}
311323

312324
function getAuditResult(audit: AuditReport, isHtml = false): string {

0 commit comments

Comments
 (0)