npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

markstream-cli

v0.0.2

Published

Stream Markdown to real terminals with ANSI rendering and async syntax highlighting

Downloads

60

Readme

markstream-cli

Stream-render Markdown in a real terminal (with optional async code highlighting).

Install

pnpm add markstream-cli
# or: npm i markstream-cli
# or: yarn add markstream-cli

CLI

cat README.md | markstream --theme nord --final-only
markstream ./README.md --no-color
markstream --help

--theme <theme> enables Shiki ANSI highlighting, even when stdout is piped. Use --no-color to disable ANSI styling and syntax highlighting.

Usage

One-shot streaming to terminal:

import { createShikiHighlightCode, streamMarkdownToTerminal } from 'markstream-cli'

async function* chunks() {
  yield '# Hello\n\n'
  yield '```ts\nconst x = 1\n'
  yield '```\n'
}

await streamMarkdownToTerminal(chunks(), {
  terminal: { clear: true },
  // Optional debug instrumentation:
  // debug: { patches: true },
  render: {
    highlightCode: createShikiHighlightCode({ theme: 'nord' as any }),
  },
})

Demos (repo)

These require a real TTY (run in an interactive terminal; not captured output).

  • pnpm run demo:stream: character-by-character markdown streaming + code fence completion
  • pnpm run demo:highlight-md: stream a larger markdown fixture + async code highlighting
  • pnpm test: run unit tests

Styling notes (terminal)

**strong** is rendered using ANSI "bold" (SGR 1). Whether it looks bold depends on your terminal + font/theme:

  • Some terminals/fonts show little/no difference for bold text (it may map to a brighter color instead).
  • VS Code integrated terminal can look subtle depending on your font and theme.

If you need strong to be visually obvious everywhere, override the render theme:

await streamMarkdownToTerminal(chunks(), {
  render: {
    // Make strong more visible across terminals:
    theme: { strong: { bold: true, underline: true } },
  },
})

Advanced: low-level renderer

If you want to manage terminal I/O yourself (or integrate with another terminal abstraction), use createMarkdownStreamRenderer():

import { createMarkdownStreamRenderer } from 'markstream-cli'

const r = createMarkdownStreamRenderer({
  strategy: 'smart', // append when possible
  render: { color: true },
})

process.stdout.write(r.push('# Title\n\nHello **world**.\n'))
process.stdout.write(r.push('```ts\nconst x = 1\n'))
process.stdout.write(r.push('```'))
for (const patch of await r.flush())
  process.stdout.write(patch)

Security

Markdown text is sanitized by default before it is written to the terminal, so raw ESC/BEL/C1 control sequences from untrusted input are rendered as visible symbols instead of being executed by the terminal. Custom highlightCode functions receive sanitized code by default unless render.allowControlSequences is enabled.

To allow raw control sequences from Markdown code blocks to reach Shiki output, enable both render.allowControlSequences: true and createShikiHighlightCode({ theme, allowControlSequences: true }). The render option controls whether raw Markdown input is sanitized before it reaches the highlighter; the Shiki option controls whether Shiki token content is sanitized before ANSI styling is applied.

The string returned from a custom highlighter is treated as trusted terminal output, because highlighters are expected to emit ANSI styling; use trusted highlighters only.

Troubleshooting

  • Nothing updates / looks wrong when piping: streaming requires a TTY. For programmatic usage set terminal.stream.isTTY = true only if your target really is a terminal.
  • Flicker during rewrites: prefer streamMarkdownToTerminal() (it uses synchronized updates and streaming-friendly patching), or set strategy: 'smart' unless you need full redraw behavior.

:coffee:

buy me a cup of coffee

License

MIT

Sponsors