From 11e5c9d5a7edd4f340378f7b43f01d98c24447d1 Mon Sep 17 00:00:00 2001 From: Fadhlan Date: Fri, 3 Jul 2026 14:47:16 +0700 Subject: [PATCH] fix: preserve markdown code fences in fancy reporter --- src/reporters/fancy.ts | 4 ++-- test/consola.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/reporters/fancy.ts b/src/reporters/fancy.ts index 3c58b277..8d3b3225 100644 --- a/src/reporters/fancy.ts +++ b/src/reporters/fancy.ts @@ -137,8 +137,8 @@ export class FancyReporter extends BasicReporter { function characterFormat(str: string) { return ( str - // highlight backticks - .replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)) + // Highlight inline code without consuming Markdown fence backticks. + .replace(/(? colors.cyan(m)) // underline underscores .replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `) ); diff --git a/test/consola.test.ts b/test/consola.test.ts index ae9e177f..7f3af501 100644 --- a/test/consola.test.ts +++ b/test/consola.test.ts @@ -1,5 +1,6 @@ import { describe, test, expect } from "vitest"; import { ConsolaReporter, LogLevels, LogObject, createConsola } from "../src"; +import { FancyReporter } from "../src/reporters/fancy"; describe("consola", () => { test("can set level", () => { @@ -56,6 +57,30 @@ describe("consola", () => { expect(logs.at(-1)!.args).toEqual(["SPAM", "(repeated 4 times)"]); }); + + test("fancy reporter preserves markdown code fences", () => { + const reporter = new FancyReporter(); + const message = [ + "```html", + "
hello
", + "```", + "```html", + "
hello
", + "```", + ].join("\n"); + + const output = reporter.formatLogObj( + { + type: "log", + level: LogLevels.log, + date: new Date(), + args: [message], + }, + {}, + ); + + expect(output.match(/```html\n
hello<\/div>\n```/g)).toHaveLength(2); + }); }); function wait(delay) {