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

Options

Output

Generates HTML with syntax highlighting applied to:

Examples

Generate HTML for a File

nmbl color src/Services/MyService.cs --output output/MyService.html

Creates an HTML file with syntax-highlighted code.

Output to Console

nmbl color src/Program.cs

Displays HTML to the console (useful for piping to other tools).

With Line Numbers

nmbl color src/Controllers/HomeController.cs --line-numbers --output highlighted.html

Includes 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"
done

Use Cases

Documentation Generation

# Highlight code samples for documentation
nmbl color src/Examples/QuickStart.cs --output docs/examples/quick-start.html

Create highlighted code snippets for your documentation.

Code Review Artifacts

# Generate highlighted version for review
nmbl color src/NewFeature.cs --line-numbers --output review/NewFeature.html

Make 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.html

Generate beautiful code snippets for technical blog posts.

Presentation Materials

# Highlight code for presentations
nmbl color demo/LiveDemo.cs --output presentation/demo-code.html

Create professional-looking code slides.

Code Sharing

# Share code with syntax highlighting
nmbl color src/Solution.cs --output shared/solution.html

Share code with colleagues while preserving formatting.

HTML Output

The generated HTML includes:

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 page

Then extract the <pre><code> block to embed in your own HTML.

Styling

The output uses standard CSS classes, allowing you to:

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"
done

Include 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