Introduction to Marked-Terminal
Marked-terminal is a powerful library that allows developers to render beautiful Markdown in the terminal. This package integrates Marked with the terminal to provide a feature-rich Markdown renderer for Node.js environments. Let’s explore its features and APIs.
Getting Started
To start using marked-terminal, you can install it via npm:
npm install marked-terminal
Basic Usage
Here is a simple example of how to use marked-terminal:
const marked = require('marked');
const TerminalRenderer = require('marked-terminal');
// Set marked to use the TerminalRenderer
marked.setOptions({
renderer: new TerminalRenderer()
});
const markdown = '# Hello, Markdown!';
console.log(marked(markdown));
Customizing the Renderer
Marked-terminal allows you to customize the renderer to fit your needs. You can override various options:
const renderer = new TerminalRenderer({
heading: chalk.bold.cyan,
list: {
padding: 2
},
href: text => chalk.underline.blue(text)
});
marked.setOptions({
renderer: renderer
});
const markdown = '[Visit GitHub](https://github.com)';
console.log(marked(markdown));
Advanced Features
Marked-terminal supports advanced features like handling tables, images, and custom tokens:
const renderer = new TerminalRenderer();
marked.setOptions({
renderer: renderer,
smartLists: true
});
const markdown = \`
| Feature | Support |
|------------|---------|
| Tables | Yes |
| Images | Yes |
| Custom Tokens | Yes |
\`;
console.log(marked(markdown));
Full App Example
Here is a full example of a Node.js application using marked-terminal:
const express = require('express');
const marked = require('marked');
const TerminalRenderer = require('marked-terminal');
const app = express();
marked.setOptions({
renderer: new TerminalRenderer()
});
app.get('/', (req, res) => {
const markdown = '# Hello, World!\\n' +
'Welcome to the **marked-terminal** application!';
res.send(marked(markdown));
});
app.listen(3000, () => {
console.log('App running on http://localhost:3000');
});
With this app, you can create a simple web server that renders Markdown content in the terminal.
Hash: 5f262654f54aa7bbb68300f1c32e73a6c9f6c4c4ab6cb77c02a676ee2adc2e56