SimpleFormatter 1.0.0

dotnet add package SimpleFormatter --version 1.0.0
                    
NuGet\Install-Package SimpleFormatter -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SimpleFormatter" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimpleFormatter" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SimpleFormatter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SimpleFormatter --version 1.0.0
                    
#r "nuget: SimpleFormatter, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SimpleFormatter@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SimpleFormatter&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SimpleFormatter&version=1.0.0
                    
Install as a Cake Tool

SimpleFormatter

Lightweight C-style language formatter that tokenizes code and renders HTML with CSS classes for styling.

Supported languages: C#, Java, C++, JavaScript, TypeScript.

Usage

var code = """
// hi
var msg = "Hello";
""";
var html = SimpleFormatter.SimpleCStyleLanguageFormatter.FormatCodeToHtml(code, new SimpleFormatter.CSharpFormatter());

Purpose

A simple formatter that supports C styles languages (C++, C#, Java, JS, TS) not requring external libs. The objective is to provide a good enough formatting for reading without the need for a real parser.

Implementation

The formatter is implemented in C# as a library and a command line tool. It targets .NET 10.0 and uses C# 14.0 features.

Files

  • SimpleFormatter (library)

    • SimpleFormatter/ILanguageFormatter.cs � Language contract (identifier/operator helpers, Keywords, Theme) and CSS generator for themes.
    • SimpleFormatter/ICodeFormatter.cs � Base interface for code formatters (FormatCodeToHtml).
    • SimpleFormatter/SimpleCStyleLanguageFormatter.cs � Core tokenizer and HTML renderer (markers, guides, line numbers).
    • SimpleFormatter/Language.csBaseCStyleFormatter and concrete formatters: CSharpFormatter, JavaFormatter, CppFormatter, JavaScriptFormatter, TypeScriptFormatter.
    • SimpleFormatter/TokenType.cs � Token kind enumeration used by tokenization/formatting.
    • SimpleFormatter/SyntaxTheme.cs � Theme system, token-type?CSS-class mapping, default styles and colors.
    • SimpleFormatter/BaseDarkSyntaxTheme.cs � Base dark theme deriving from SyntaxTheme.
    • SimpleFormatter/CSharpSyntaxTheme.cs � C# theme tweaks.
    • SimpleFormatter/JavaSyntaxTheme.cs � Java theme tweaks.
    • SimpleFormatter/JavaScriptSyntaxTheme.cs � JavaScript theme tweaks.
    • SimpleFormatter/TypeScriptSyntaxTheme.cs � TypeScript theme tweaks.
    • SimpleFormatter/CppSyntaxTheme.cs � C++ theme tweaks.
    • SimpleFormatter/ThemeStyle.cs � Simple style holder used by SyntaxTheme.
  • SimpleFormatter.Samples (console)

    • SimpleFormatter.Samples/Program.cs � Generates sample HTML pages for manual inspection.
  • SimpleFormatter.Tests (MSTest)

    • SimpleFormatter.Tests/VisualOutputTests.cs � Produces HTML artifacts for multiple languages and real-world code; emits per-language CSS.

Class diagram

classDiagram
    class ICodeFormatter {
      +string FormatCodeToHtml(string)
      +ILanguageFormatter GetLanguage()
    }
    class ILanguageFormatter {
      +HashSet~string~ Keywords
      +SyntaxTheme Theme
      +string GetCss()
      +bool IsOperatorChar(char)
      +bool IsIdentStart(char)
      +bool IsIdentPart(char)
      +string LanguageName
    }
    class BaseCStyleFormatter
    class CSharpFormatter
    class JavaFormatter
    class CppFormatter
    class JavaScriptFormatter
    class TypeScriptFormatter

    class SimpleCStyleLanguageFormatter
    class SyntaxTheme {
      +int CharacterWidthPerTab
    }
    class BaseDarkSyntaxTheme
    class CSharpSyntaxTheme
    class JavaSyntaxTheme
    class JavaScriptSyntaxTheme
    class TypeScriptSyntaxTheme
    class CppSyntaxTheme

    class ThemeStyle {
      +string InlineStyle
    }
    class TokenType

    ILanguageFormatter <|.. BaseCStyleFormatter
    BaseCStyleFormatter <|-- CSharpFormatter
    BaseCStyleFormatter <|-- JavaFormatter
    BaseCStyleFormatter <|-- CppFormatter
    BaseCStyleFormatter <|-- JavaScriptFormatter
    BaseCStyleFormatter <|-- TypeScriptFormatter

    SyntaxTheme <|-- BaseDarkSyntaxTheme
    BaseDarkSyntaxTheme <|-- CSharpSyntaxTheme
    BaseDarkSyntaxTheme <|-- JavaSyntaxTheme
    BaseDarkSyntaxTheme <|-- JavaScriptSyntaxTheme
    BaseDarkSyntaxTheme <|-- TypeScriptSyntaxTheme
    BaseDarkSyntaxTheme <|-- CppSyntaxTheme

    SimpleCStyleLanguageFormatter ..> ILanguageFormatter : uses
    ILanguageFormatter --> SyntaxTheme : Theme
    SyntaxTheme o--> ThemeStyle : Data
    SimpleCStyleLanguageFormatter ..> TokenType : tokenizes
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 110 1/15/2026