Skip to content

Commit 0f1bfa6

Browse files
committed
logPandoc, logPandocJSON - use pandoc -t ansi to produce nicely-formatted output
1 parent 003e6e2 commit 0f1bfa6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/core/log.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import { lines } from "./text.ts";
1919
import { debug, error, getLogger, setup, warning } from "../deno_ral/log.ts";
2020
import { asErrorEx, InternalError } from "./lib/error.ts";
2121
import { onCleanup } from "./cleanup.ts";
22+
import { execProcess } from "./process.ts";
23+
import { pandocBinaryPath } from "./resources.ts";
24+
import { Block, pandoc } from "./pandoc/json.ts";
2225

2326
export type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR";
2427

@@ -459,3 +462,33 @@ const levelMap: Record<
459462
warning: "WARN",
460463
error: "ERROR",
461464
};
465+
466+
export async function logPandocJson(
467+
blocks: Block[],
468+
) {
469+
const src = JSON.stringify(pandoc({}, blocks), null, 2);
470+
return logPandoc(src, "json");
471+
}
472+
473+
export async function logPandoc(
474+
src: string,
475+
format: string = "markdown",
476+
) {
477+
const cols = Deno.consoleSize().columns;
478+
const result = await execProcess({
479+
cmd: [
480+
pandocBinaryPath(),
481+
"-f",
482+
format,
483+
"-t",
484+
"ansi",
485+
`--columns=${cols}`,
486+
],
487+
stdout: "piped",
488+
}, src);
489+
if (result.code !== 0) {
490+
error(result.stderr);
491+
} else {
492+
log.info(result.stdout);
493+
}
494+
}

0 commit comments

Comments
 (0)