Skip to content

feat(cli): add --format option for html output#1211

Merged
antfu merged 1 commit intoshikijs:mainfrom
Divyapahuja31:feat/cli-html-format
Dec 4, 2025
Merged

feat(cli): add --format option for html output#1211
antfu merged 1 commit intoshikijs:mainfrom
Divyapahuja31:feat/cli-html-format

Conversation

@Divyapahuja31
Copy link
Copy Markdown
Contributor

Description

This PR introduces a new --format option to the @shikijs/cli, enabling users to output syntax-highlighted code as HTML, in addition to the existing ANSI terminal output.

Changes:

  • Added --format <format> flag (supports ansi | html, default: ansi).
  • Integrated codeToHtml for HTML output generation.
  • Added comprehensive test case for the new option.
  • Updated CLI documentation.

Why this is valuable:

  1. Scripting & Automation: Users can now easily pipe highlighted HTML into files for static sites, documentation, or reports without writing custom Node.js scripts.
    • Example: npx shiki-cli file.js --format html > snippet.html
  2. Debugging: Provides a quick way for maintainers and users to inspect the exact HTML output Shiki generates for a specific code/theme combination directly from the terminal.
  3. Feature Parity: Aligns Shiki CLI with other standard highlighting tools (like pygments) that support multiple output formats.

Implementation Details:

  • The implementation leverages the existing codeToHtml function from the core package, ensuring consistent output with the main library.
  • The default behavior remains unchanged (ANSI output), ensuring no breaking changes for existing workflows.

Verification:

  • Added a new test in packages/cli/test/cli.test.ts to verify that --format html correctly produces an HTML string with the expected class names.
  • Ran pnpm test packages/cli -> All tests passed.
  • Ran pnpm build -> Build successful.

@netlify
Copy link
Copy Markdown

netlify bot commented Dec 3, 2025

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 91bd284
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/6930ab2096de4d00082e0dc4
😎 Deploy Preview https://deploy-preview-1211--shiki-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify bot commented Dec 3, 2025

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 91bd284
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/6930ab204d280f0008d5c02f
😎 Deploy Preview https://deploy-preview-1211--shiki-matsu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.20%. Comparing base (61c87e8) to head (91bd284).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1211   +/-   ##
=======================================
  Coverage   95.20%   95.20%           
=======================================
  Files          92       92           
  Lines        7922     7922           
  Branches     1689     1689           
=======================================
  Hits         7542     7542           
  Misses        374      374           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@antfu antfu merged commit 28dd090 into shikijs:main Dec 4, 2025
14 checks passed
This was referenced Feb 5, 2026
This was referenced Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants