color - Syntax Highlighted Code
Overview
The color command generates syntax-highlighted HTML from C# code files. It creates beautiful, colorized code output with VS Code Dark+ inspired styling, making code easier to read and present in documentation, blog posts, or code reviews.
Syntax
nmbl color <FilePath> [options]Arguments
FilePath- Path to a C# (.cs) file
Options
--output <path>- Output HTML file path (optional, defaults to console output)--line-numbers- Include line numbers in the output--theme <name>- Color theme to use (default: vscode-dark)
Output
Generates HTML with syntax highlighting applied to:
- Keywords (public, class, if, etc.)
- Types (string, int, custom classes)
- Strings and literals
- Comments
- Method names
- Operators
Examples
Generate HTML for a File
nmbl color src/Services/MyService.cs --output output/MyService.htmlCreates an HTML file with syntax-highlighted code.
Output to Console
nmbl color src/Program.csDisplays HTML to the console (useful for piping to other tools).
With Line Numbers
nmbl color src/Controllers/HomeController.cs --line-numbers --output highlighted.htmlIncludes line numbers in the output for easier reference.
Batch Process Multiple Files
# Unix/Linux
for file in src/**/*.cs; do
nmbl color "$file" --output "output/$(basename $file .cs).html"
doneUse Cases
Documentation Generation
# Highlight code samples for documentation
nmbl color src/Examples/QuickStart.cs --output docs/examples/quick-start.htmlCreate highlighted code snippets for your documentation.
Code Review Artifacts
# Generate highlighted version for review
nmbl color src/NewFeature.cs --line-numbers --output review/NewFeature.htmlMake code easier to review in HTML format.
Blog Post Preparation
# Create highlighted code for blog posts
nmbl color samples/Tutorial.cs --output blog/code-sample.htmlGenerate beautiful code snippets for technical blog posts.
Presentation Materials
# Highlight code for presentations
nmbl color demo/LiveDemo.cs --output presentation/demo-code.htmlCreate professional-looking code slides.
Code Sharing
# Share code with syntax highlighting
nmbl color src/Solution.cs --output shared/solution.htmlShare code with colleagues while preserving formatting.
HTML Output
The generated HTML includes:
- Embedded CSS styles (no external dependencies)
- Proper semantic HTML structure
- VS Code Dark+ color scheme
- Responsive layout
- Print-friendly styling
Example Output Structure
<!DOCTYPE html>
<html>
<head>
<style>
/* Embedded VS Code Dark+ inspired styles */
</style>
</head>
<body>
<pre><code>
<!-- Syntax-highlighted code -->
</code></pre>
</body>
</html>Customization
Embedding in Your Site
# Generate just the code block
nmbl color src/Example.cs > code-block.html
# Embed in your pageThen extract the <pre><code> block to embed in your own HTML.
Styling
The output uses standard CSS classes, allowing you to:
- Override colors in your own stylesheet
- Adjust font sizes and spacing
- Customize the theme
Tips
Create a Documentation Build Script
#!/bin/bash
# highlight-docs.sh
mkdir -p docs/code
# Highlight all example files
for example in examples/*.cs; do
name=$(basename "$example" .cs)
nmbl color "$example" --line-numbers --output "docs/code/$name.html"
doneInclude in CI/CD
# Generate highlighted code as build artifact
- name: Generate Code Highlights
run: |
mkdir highlighted
for file in src/Examples/*.cs; do
nmbl color "$file" --output "highlighted/$(basename $file .cs).html"
done
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: code-highlights
path: highlighted/Compare Code Versions
# Highlight before and after refactoring
git show HEAD~1:src/Service.cs > /tmp/before.cs
nmbl color /tmp/before.cs --output before.html
nmbl color src/Service.cs --output after.html
# Open both in browser for side-by-side comparison