Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/reporters/fancy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?<!`)`([^`\n]+)`(?!`)/g, (_, m) => colors.cyan(m))
// underline underscores
.replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `)
);
Expand Down
25 changes: 25 additions & 0 deletions test/consola.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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",
"<div>hello</div>",
"```",
"```html",
"<div>hello</div>",
"```",
].join("\n");

const output = reporter.formatLogObj(
{
type: "log",
level: LogLevels.log,
date: new Date(),
args: [message],
},
{},
);

expect(output.match(/```html\n<div>hello<\/div>\n```/g)).toHaveLength(2);
});
});

function wait(delay) {
Expand Down