Skip to content

Conversation

@SHUBHI-KUMARI
Copy link

@SHUBHI-KUMARI SHUBHI-KUMARI commented Dec 4, 2025

Description

This PR adds a new transformer transformerNotationFold to @shikijs/transformers. This transformer allows users to mark sections of code as foldable using comment notation, similar to VS Code or Monaco Editor.

It supports two syntaxes:

  1. Shiki-style: // [!code fold:start] and // [!code fold:end]
  2. Region-style: // #region and // #endregion

Changes

  • Added packages/transformers/src/transformers/notation-fold.ts
  • Exported transformerNotationFold in packages/transformers/src/index.ts
  • Added tests in packages/transformers/test/fold.test.ts

Usage

Shiki Syntax

// [!code fold:start] variables
let a = 1
// [!code fold:end]

Region Syntax

// #region variables
let a = 1
// #endregion

Implementation Details

The transformer adds the following classes to the generated HTML:

  • fold-start: Added to the line containing the start marker (for #region) or the line following the start marker (for [!code fold:start]).
  • fold-end: Added to the line containing the end marker (for #endregion) or the line preceding the end marker (for [!code fold:end]).
  • fold-content: Added to all lines between the start and end lines.

Note: Shiki-style markers ([!code fold:...]) are removed from the output, while #region markers are preserved (but still get the classes).

Verification

Added a new test file packages/transformers/test/fold.test.ts which verifies:

  • Correct class application for both syntaxes.
  • Nested folding support (via stack implementation).
  • Correct handling of line removal for Shiki markers.

closes: #861

@netlify
Copy link

netlify bot commented Dec 4, 2025

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 39c2cbe
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/6931bfff96d9820008e8008c
😎 Deploy Preview https://deploy-preview-1219--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

netlify bot commented Dec 4, 2025

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 39c2cbe
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/6931bfffffc4660008fbb58b
😎 Deploy Preview https://deploy-preview-1219--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

codecov bot commented Dec 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.27%. Comparing base (28dd090) to head (39c2cbe).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1219      +/-   ##
==========================================
+ Coverage   95.20%   95.27%   +0.06%     
==========================================
  Files          92       93       +1     
  Lines        7922     8034     +112     
  Branches     1689     1708      +19     
==========================================
+ Hits         7542     7654     +112     
  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.

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.

@shikijs/transformers: add transformerFold

1 participant