From bbed1223aa93b894c25c9dbef0d684c03a4a3319 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 27 Jun 2023 18:18:31 +0200 Subject: [PATCH] fix(fancy): style underscore with surrounding spaces (resolves #203) --- examples/special.ts | 4 +++- src/reporters/fancy.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/special.ts b/examples/special.ts index 1c4b6ccb..3325c77b 100755 --- a/examples/special.ts +++ b/examples/special.ts @@ -18,7 +18,9 @@ consola.error(undefined, null, false, true, Number.NaN); consola.log("We can `monospace` keyword using grave accent charachter!"); -consola.log("We can also _underline_ words!"); +consola.log( + "We can also _underline_ words but not_this or this should_not_be_underlined!" +); // Nonstandard error const { message, stack } = new Error("Custom Error!"); diff --git a/src/reporters/fancy.ts b/src/reporters/fancy.ts index 2ed42e8c..ae9e19ce 100644 --- a/src/reporters/fancy.ts +++ b/src/reporters/fancy.ts @@ -129,7 +129,7 @@ function characterFormat(str: string) { // highlight backticks .replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)) // underline underscores - .replace(/_([^_]+)_/gm, (_, m) => colors.underline(m)) + .replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `) ); }