Quickstart
This guide will help you create your first syntax-highlighted code block with Code Syntactic Sugar in under 5 minutes.Prerequisites
Make sure you have:- A React project set up (React 18 or 19)
- Code Syntactic Sugar installed (see installation guide)
Import the highlight function
Import the
highlight function from code-syntactic-sugar in your React component:Create a code block component
Create a simple component that highlights code:The
highlight function takes your code string and returns React elements ready to render.Add CSS for styling
Create a CSS file and import it in your application. Add the following CSS variables to customize the syntax highlighting colors:
All class names use the
--css- prefix. You can customize these CSS variables to match your theme.Add line modifiers
One of the powerful features of Code Syntactic Sugar is the ability to highlight, add, or remove specific lines. Here’s how:Line numbers start at 1. If multiple modifiers are applied to the same line, the precedence order is: highlighted → added → removed.
Add line numbers
To display line numbers next to your code, add this CSS:Next steps
Now that you have basic syntax highlighting working, you can:- Customize token colors using CSS class names like
.css__token--keyword - Experiment with different line modifier combinations
- Create custom themes by adjusting CSS variables
- Explore advanced styling options
Advanced customization
Learn more about customizing colors, themes, and advanced features in the full documentation