diff --git a/src/cli/utils.ts b/src/cli/utils.ts index 80eb71c..46dceac 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -215,15 +215,14 @@ export function renderOutput( console.log(toMarkdownTable( output, outputFormat === "alignedtable" || outputFormat === "prettytable", - outputFormat === "prettytable", headerSpec, )); } else if (outputFormat === "alignedtable") { - console.log(toMarkdownTable(output, true, false, headerSpec)); + console.log(toMarkdownTable(output, true, headerSpec)); } else if (outputFormat === "prettytable") { - console.log(toMarkdownTable(output, true, true, headerSpec)); + console.log(toMarkdownTable(output, true, headerSpec)); } else if (outputFormat === "table") { - console.log(toMarkdownTable(output, false, false, headerSpec)); + console.log(toMarkdownTable(output, false, headerSpec)); } else { console.log(JSON.stringify(output, null, 2)); } diff --git a/src/markdown.ts b/src/markdown.ts index bcba7ab..ed625f2 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -17,6 +17,25 @@ function formatCell(value: unknown): string { return text.replaceAll("|", "\\|").replaceAll("\n", "
"); } +const inlineCodePredicates = [ + (value: Scalar): boolean => isGuid(value), + (value: Scalar): boolean => + typeof value === "string" + && /^(?:\d{1,3}\.){3}\d{1,3}(?:\/(?:\d{1,2}|(?:\d{1,3}\.){3}\d{1,3}))?$/.test(value), +]; + +function renderCell(raw: Scalar): string { + const text = formatCell(raw); + + for (const predicate of inlineCodePredicates) { + if (predicate(raw)) { + return `\`${text}\``; + } + } + + return text; +} + function isGuid(value: unknown): value is string { return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value); @@ -88,7 +107,6 @@ function getScalarRowsAndHeaders(value: unknown): { headers: string[]; rows: Sca export function toMarkdownTable( value: unknown, pretty = false, - quoteGuids = false, headerSpec: HeaderSpec = { mode: "default" }, ): string { const { headers, rows } = getScalarRowsAndHeaders(value); @@ -104,11 +122,6 @@ export function toMarkdownTable( return { key, label }; }); - const renderCell = (raw: Scalar): string => { - const text = formatCell(raw); - return quoteGuids && isGuid(raw) ? `\`${text}\`` : text; - }; - if (!pretty) { const headerLine = `| ${headerDefinitions.map((h) => h.label).join(" | ")} |`; const separatorLine = `| ${headerDefinitions.map(() => "---").join(" | ")} |`;