{"name":"marked-terminal","version":"5.2.1","keywords":["marked","render","terminal","markdown","markdown-to-terminal"],"author":{"name":"Mikael Brevik"},"license":"MIT","_id":"marked-terminal@5.2.1","maintainers":[{"name":"mikaelb","email":"mikaelbre@gmail.com"}],"homepage":"https://github.com/mikaelbr/marked-terminal","bugs":{"url":"https://github.com/mikaelbr/marked-terminal/issues"},"dist":{"shasum":"3f160dc5460d04520f36bdccadaad1734d2f416a","tarball":"http://registry-npm.ywwl.com/marked-terminal/download/marked-terminal-5.2.1.tgz","fileCount":5,"integrity":"sha512-ZGLqRRCsC3VuTHgZM3NdOMU1p0/9ynWeAF+qtQqrWWAVCsI7Dc3VIAYKD71HkTG97qWB0XMPBUTd6RxAmixAdw==","signatures":[{"sig":"MEUCIBW+W4jxYcTyL6bV6o3wJF7GDbtwPolQehXFC834zzOHAiEAyKofsMjcfOn/kTrBgBVTSjjebdTvf4kItYLFiwOxB0M=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIFtAUL5vw1cxQa4ksq9EUQsuVXeFqLrujBlDxNXLd9CMAiEAwAzrFNCNzdnq2ZU6+yYmJk16sYfrv4rHL2TGf3Si4pI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":53510,"size":13405,"noattachment":false,"key":"/marked-terminal/-/marked-terminal-5.2.1.tgz"},"main":"./index.cjs","type":"module","browser":"./index.js","engines":{"node":">=14.13.1 || >=16.0.0"},"exports":{"node":{"import":"./index.js","require":"./index.cjs"},"default":"./index.js"},"scripts":{"test":"FORCE_HYPERLINK=0 mocha tests/*.js --reporter spec","build":"rollup -c","prepack":"npm run build"},"_npmUser":{"name":"mikaelb","email":"mikaelbre@gmail.com"},"repository":{"url":"git+https://github.com/mikaelbr/marked-terminal.git","type":"git"},"_npmVersion":"11.16.0","description":"A custom render for marked to output to the Terminal","directories":{"example":"example"},"_nodeVersion":"26.3.0","dependencies":{"chalk":"^5.2.0","cardinal":"^2.1.1","cli-table3":"^0.6.3","node-emoji":"^1.11.0","ansi-escapes":"^6.2.0","supports-hyperlinks":"^2.3.0"},"publishConfig":{"tag":"release-5.x"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"mocha":"^10.2.0","marked":"^5.0.1","rollup":"^3.21.5","@rollup/plugin-commonjs":"^24.1.0","@rollup/plugin-node-resolve":"^15.0.2"},"peerDependencies":{"marked":"^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/marked-terminal_5.2.1_1793215994592_0.680940535915521","host":"s3://npm-registry-packages-npm-production"},"readme":"# marked-terminal\n\n> Custom Renderer for [marked](https://github.com/markedjs/marked)\n> allowing for printing Markdown to the Terminal. Supports pretty tables, syntax\n> highlighting, and overriding all colors and styles.\n\nCould for instance be used to print usage information.\n\n[![build](https://github.com/mikaelbr/marked-terminal/actions/workflows/ci.yml/badge.svg)](https://github.com/mikaelbr/marked-terminal/actions/workflows/ci.yml) [![npm marked-terminal](https://img.shields.io/npm/v/marked-terminal.svg)](https://www.npmjs.com/package/marked-terminal)\n\n## Install\n\n```sh\npnpm add marked marked-terminal\n```\n\nRequires a Node.js LTS version (>= 22.12) and marked >= 13. TypeScript types are included.\n\n## Example\n\n```ts\nimport { marked } from 'marked';\nimport { markedTerminal } from 'marked-terminal';\n\nmarked.use(markedTerminal([options][, highlightOptions]));\n\nconsole.log(marked.parse('# Hello \\n This is **markdown** printed in the `terminal`'));\n```\n\nThe package is ESM-only. It can still be loaded with `require()` from CommonJS,\nwhich is supported natively from Node.js 22.12:\n\n```js\nconst { marked } = require('marked');\nconst { markedTerminal } = require('marked-terminal');\n```\n\nThis will produce the following:\n\n![Screenshot of marked-terminal](./screenshot.png)\n\n## CLI\n\nmarked-terminal also comes with a command line tool, `mt`, for rendering\nMarkdown files or piped input directly from bash, PowerShell and other shells:\n\n```sh\npnpm dlx marked-terminal README.md   # without installing\npnpm add -g marked marked-terminal\nmt README.md\ncat CHANGELOG.md | mt --width 60\n```\n\nThe CLI wraps text and tables to the terminal width (at most 100 columns) and\nindents with 2 spaces. Colors are turned off when output isn't a terminal or\n`NO_COLOR` is set. Several files can be passed at once, and `-` reads from\nstdin.\n\n```\nUsage: mt [options] [file ...]\n\nRender Markdown to the terminal. Reads from stdin when no file is given,\nor when file is \"-\".\n\nOptions:\n  -f, --file <path>       Markdown file to render (same as passing it as an argument)\n  -w, --width <columns>   Width to wrap text and tables at\n                          (default: terminal width, at most 100)\n      --no-reflow         Don't wrap text and tables to the width\n      --color             Force colors, even when not writing to a terminal\n      --no-color          Disable colors (also respects NO_COLOR)\n      --no-emoji          Don't replace :emoji: codes with emojis\n      --no-section-prefix Don't prefix headings with #\n      --no-images         Show images as text instead of drawing them\n      --remote-images     Download and draw http(s) images\n  -h, --help              Show this help\n  -v, --version           Show version\n\nExamples:\n  mt README.md\n  cat CHANGELOG.md | mt --width 60\n  pnpm dlx marked-terminal README.md\n```\n\nThe CLI draws images in the terminal, resolving paths relative to the\nMarkdown file (or the current directory for stdin). Remote images are only\ndownloaded with `--remote-images`. When output isn't a terminal, images are\nprinted as text. See [Images](#images).\n\n### Images\n\nSet `images` to draw images in the terminal instead of printing them as\n`![alt](href)`:\n\n```ts\nmarked.use(markedTerminal({ images: true }));\n\nconsole.log(await marked.parse('![Logo](./logo.png)'));\n```\n\nImages are loaded asynchronously, so `marked.parse` returns a promise when\n`images` is set. How images are drawn depends on the terminal:\n\n| Terminal                                       | Images                                   |\n| ---------------------------------------------- | ---------------------------------------- |\n| iTerm2, WezTerm, VS Code, Konsole, mintty, Rio | Full resolution (iTerm2 protocol)        |\n| Kitty, Ghostty, Warp                           | Full resolution for PNGs (Kitty protocol), others pixelated |\n| Other terminals, tmux and screen               | Pixelated, with colored half blocks      |\n| Output that isn't a terminal                   | Printed as text, as without `images`     |\n\nTry it in your terminal with `node example/images.ts`, optionally passing\n`kitty`, `iterm2` or `ansi` to force a protocol.\n\nPixelated images are drawn by [terminal-image](https://github.com/sindresorhus/terminal-image),\nwhich supports PNG, JPEG, GIF and BMP. Other formats, and images that can't be\nloaded, are printed as text.\n\n`images` can also be an object of options:\n\n```ts\nmarkedTerminal({\n  images: {\n    // Directory relative image paths are resolved from (default: cwd)\n    baseDir: '/path/to/docs',\n    // Download http(s) images. Off by default, so rendering untrusted\n    // Markdown doesn't make network requests.\n    remote: false,\n    // Largest image to load, in bytes (default: 10 MB)\n    maxBytes: 10 * 1024 * 1024,\n    // Maximum width in columns (default: the output width)\n    width: 60,\n    // Force 'kitty', 'iterm2' or 'ansi' (pixelated) instead of detecting it\n    protocol: undefined\n  }\n});\n```\n\n### Syntax Highlighting\n\nCode blocks are syntax highlighted using [emphasize](https://github.com/wooorm/emphasize)\n(highlight.js). You can override highlighting defaults by passing in settings as the second argument.\n\nHaving the following markdown input:\n\n<pre>\n```js\nvar foo = function(bar) {\n  console.log(bar);\n};\nfoo('Hello');\n```\n</pre>\n\n...we will convert it into terminal format:\n\n```ts\nconsole.log(marked.parse(exampleSource));\n```\n\nThis will produce the following:\n\n![Screenshot of marked-terminal](./screenshot2.png)\n\n## API\n\n```ts\nmarkedTerminal(options?: TerminalRendererOptions, highlightOptions?: HighlightOptions): MarkedExtension\n```\n\n### `options`\n\nOptional. Used to override default styling. Every style is a plain\n`(text: string) => string` function, so you can use `node:util`'s `styleText`,\n`chalk`, `picocolors` or your own functions.\n\nDefault values are:\n\n```ts\nimport { styleText } from 'node:util';\n\nconst defaultOptions = {\n  // Colors\n  code: (s) => styleText('yellow', s),\n  blockquote: (s) => styleText(['gray', 'italic'], s),\n  html: (s) => styleText('gray', s),\n  heading: (s) => styleText(['green', 'bold'], s),\n  firstHeading: (s) => styleText(['magenta', 'underline', 'bold'], s),\n  hr: (s) => styleText('reset', s),\n  listitem: (s) => styleText('reset', s),\n  table: (s) => styleText('reset', s),\n  paragraph: (s) => styleText('reset', s),\n  strong: (s) => styleText('bold', s),\n  em: (s) => styleText('italic', s),\n  codespan: (s) => styleText('yellow', s),\n  del: (s) => styleText(['dim', 'gray', 'strikethrough'], s),\n  link: (s) => styleText('blue', s),\n  href: (s) => styleText(['blue', 'underline'], s),\n  text: (s) => s,\n\n  // Formats the bulletpoints and numbers for lists\n  list: function (body, ordered, indent) {/* ... */},\n\n  // Reflow and print-out width\n  width: 80, // only applicable when reflow is true\n  reflowText: false, // also shrinks tables wider than `width` (unless tableOptions.colWidths is set)\n\n  // Should it prefix headers?\n  showSectionPrefix: true,\n\n  // Whether or not to undo marked escaping\n  // of enitities (\" -> &quot; etc)\n  unescape: true,\n\n  // Whether or not to show emojis\n  emoji: true,\n\n  // Options passed to cli-table3\n  tableOptions: {},\n\n  // The size of tabs in number of spaces or as tab characters\n  tab: 4, // examples: 4, 2, \\t, \\t\\t\n\n  image: function (href, title, text) {}, // function for overriding the default image handling.\n\n  // Render links as clickable terminal hyperlinks instead of `text (url)`.\n  // Detected from stdout when not set.\n  hyperlinks: undefined,\n\n  // Draw images in the terminal, see Images above\n  images: false\n};\n```\n\nColors are disabled when `NO_COLOR` is set or stdout doesn't support colors,\nand can be forced with `FORCE_COLOR`.\n\n#### Example of overriding defaults\n\n```ts\nimport { styleText } from 'node:util';\n\nmarked.use(\n  markedTerminal({\n    codespan: (s) => styleText(['underline', 'magenta'], s)\n  })\n);\n```\n\n### `highlightOptions`\n\n```ts\ninterface HighlightOptions {\n  // Map of highlight.js classes (without `hljs-` prefix) to style functions.\n  // Defaults to `defaultSheet`, a theme matching marked-terminal v7.\n  sheet?: Record<string, (text: string) => string>;\n  // Languages to consider when auto-detecting code without a language tag.\n  subset?: string[];\n}\n```\n\n```ts\nimport { defaultSheet, markedTerminal } from 'marked-terminal';\n\nmarked.use(\n  markedTerminal({}, { sheet: { ...defaultSheet, keyword: (s) => styleText('magenta', s) } })\n);\n```\n\nSee [more examples](./example/)\n\n## Development\n\n```sh\npnpm install\npnpm test        # vitest, including type tests\npnpm lint        # biome\npnpm typecheck\npnpm build       # tsdown -> dist/\n```\n\n### Running examples\n\nThe examples in [`example/`](./example) are TypeScript and import straight from\n`src/`, so there's no build step. Node runs `.ts` files directly through its\nbuilt-in type stripping (unflagged since Node 22.18 / 23.6):\n\n```sh\nnode example/demo.ts               # tour of most features\nnode example/reflow.ts             # text reflow at a fixed width\nnode example/usage.ts              # CLI usage/help output\nnode example/print.ts              # render this README\nnode example/print.ts path/to.md   # render any Markdown file\n```\n\nEdits to `src/` show up on the next run, which makes the examples handy for\nchecking renderer changes by eye.\n\n## Related\n\n- [ink-markdown](https://github.com/cameronhunter/ink-markdown) - Markdown component for Ink\n","publish_time":1793215994734,"_cnpm_publish_time":1793215994734,"dist-tags":{"latest":"8.0.0","release-5.x":"5.2.1","release-6.x":"6.3.1"}}