@muxik/md-viewer
Version:
A CLI tool for rendering Markdown files with syntax highlighting and pagination, optimized for AI output content display
71 lines • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.program = void 0;
const commander_1 = require("commander");
Object.defineProperty(exports, "program", { enumerable: true, get: function () { return commander_1.program; } });
const fs_1 = require("fs");
const path_1 = require("path");
const index_1 = require("./index");
const packageJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../package.json'), 'utf8'));
commander_1.program
.name('mdview')
.description('A CLI tool for rendering Markdown files with syntax highlighting and pagination')
.version(packageJson.version)
.argument('[file]', 'Markdown file to render')
.option('-t, --theme <theme>', 'Theme to use (onedark, dark, light)', 'onedark')
.option('-w, --width <width>', 'Terminal width override', (value) => parseInt(value))
.option('-n, --line-numbers', 'Show line numbers')
.option('--no-pager', 'Disable pager and print to stdout')
.option('--list-themes', 'List available themes')
.action(async (file, options) => {
try {
if (options.listThemes) {
console.log('Available themes:');
console.log(' - onedark (default) - One Dark color scheme');
console.log(' - dark - GitHub dark theme');
console.log(' - light - GitHub light theme');
return;
}
if (!file) {
if (process.stdin.isTTY) {
commander_1.program.help();
return;
}
let content = '';
process.stdin.setEncoding('utf8');
for await (const chunk of process.stdin) {
content += chunk;
}
if (content.trim()) {
const mdview = new index_1.Mdview({
theme: options.theme,
width: options.width,
showLineNumbers: options.lineNumbers,
noPager: !options.pager
});
await mdview.renderContent(content, 'stdin');
}
return;
}
if (!(0, fs_1.existsSync)(file)) {
console.error(`Error: File "${file}" not found`);
process.exit(1);
}
const mdview = new index_1.Mdview({
theme: options.theme,
width: options.width,
showLineNumbers: options.lineNumbers,
noPager: !options.pager
});
await mdview.renderFile(file);
}
catch (error) {
console.error('Error:', error instanceof Error ? error.message : error);
process.exit(1);
}
});
if (require.main === module) {
commander_1.program.parse();
}
//# sourceMappingURL=cli.js.map