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", + "