SimpleFormatter 1.0.0
dotnet add package SimpleFormatter --version 1.0.0
NuGet\Install-Package SimpleFormatter -Version 1.0.0
<PackageReference Include="SimpleFormatter" Version="1.0.0" />
<PackageVersion Include="SimpleFormatter" Version="1.0.0" />
<PackageReference Include="SimpleFormatter" />
paket add SimpleFormatter --version 1.0.0
#r "nuget: SimpleFormatter, 1.0.0"
#:package SimpleFormatter@1.0.0
#addin nuget:?package=SimpleFormatter&version=1.0.0
#tool nuget:?package=SimpleFormatter&version=1.0.0
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.cs�BaseCStyleFormatterand 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 fromSyntaxTheme.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 bySyntaxTheme.
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 | Versions 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. |
-
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 |