Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 3, 2025

This PR fixes the issue where Shiki syntax highlighting failed when language names were provided in uppercase format (e.g., "JSON", "Python") instead of the expected lowercase format.

Problem

Previously, passing uppercase language names to the highlighting function would result in errors like:

Language "JSON" is not supported by Shiki.
Language "Python" is not supported by Shiki.

This occurred because Shiki's bundledLanguages object contains language keys in lowercase (e.g., "json", "python"), but the code was performing case-sensitive comparisons without normalization.

Solution

Updated the getHighlighter and highlight functions in src/lib/highlight.ts to normalize language names to lowercase before processing:

  1. Language validation: Convert input to lowercase before checking if it exists in the supported languages list
  2. Cache consistency: Use normalized language names in cache keys for better efficiency
  3. Highlighting: Pass normalized language names to Shiki's codeToHtml method

Benefits

  • ✅ Supports both uppercase and lowercase language names seamlessly
  • ✅ Maintains existing caching mechanism while improving cache efficiency
  • ✅ Minimal code changes with no breaking changes
  • ✅ Fallback behavior for unsupported languages remains unchanged

Example

// Both of these now work correctly:
await highlight('JSON', '{"test": true}');     // ✅ Works
await highlight('json', '{"test": true}');     // ✅ Already worked

await highlight('Python', 'print("hello")');  // ✅ Works  
await highlight('python', 'print("hello")');  // ✅ Already worked

Fixes #65.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor Author

Copilot AI commented Sep 3, 2025

@CNSeniorious000 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@codesandbox
Copy link

codesandbox bot commented Sep 3, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
Copilot AI changed the title [WIP] Need to convert lang to lowercase before highlighting Fix: Convert language names to lowercase before Shiki highlighting Sep 3, 2025
Copilot finished work on behalf of CNSeniorious000 September 3, 2025 19:23
@CNSeniorious000 CNSeniorious000 force-pushed the main branch 2 times, most recently from 263cfd3 to 99ecd7b Compare September 12, 2025 01:38
@CNSeniorious000 CNSeniorious000 force-pushed the main branch 5 times, most recently from 0dafc1f to 4cbbea5 Compare November 4, 2025 07:11
@CNSeniorious000 CNSeniorious000 marked this pull request as ready for review November 28, 2025 17:46
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.

Need to convert lang to lowercase before highlighting

2 participants