Add hover tooltips, IntelliSense completions, and compile verification to your C# documentation. Zero runtime JavaScript. Built on the same compiler that powers Visual Studio.
varList<Todo>Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists. todosList<Todo>? todos = new ListList<Todo>Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.<TodoTodoA task with a title and completion status.>{ newTodo.Todo(string Title, bool Done)A task with a title and completion status.("Learn Glo#", true), newTodo.Todo(string Title, bool Done)A task with a title and completion status.("Build docs", false),};
var pendingIEnumerable<Todo>? pending = todosList<Todo>? todos.WhereIEnumerable<Todo> IEnumerable<Todo>.Where<Todo>(Func<Todo, bool> predicate)Filters a sequence of values based on a predicate.Parameterssource — An IEnumerable`1 to filter.predicate — A function to test each element for a condition.ReturnsAn IEnumerable`1 that contains elements from the input sequence that satisfy the condition.ExceptionsArgumentNullException — source or predicate is .(tTodo t => !IEnumerable<Todo> IEnumerable<Todo>.Where<Todo>(Func<Todo, bool> predicate)Filters a sequence of values based on a predicate.Parameterssource — An IEnumerable`1 to filter.predicate — A function to test each element for a condition.ReturnsAn IEnumerable`1 that contains elements from the input sequence that satisfy the condition.ExceptionsArgumentNullException — source or predicate is .tTodo t.Donebool Todo.Done);IEnumerable<Todo>Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
ConsoleConsoleRepresents the standard input, output, and error streams for console applications. This class cannot be inherited..WriteLinevoid Console.WriteLine(string? value)Writes the specified string value, followed by the current line terminator, to the standard output stream.Parametersvalue — The value to write.ExceptionsIOException — An I/O error occurred.($"Pending: {pendingIEnumerable<Todo>? pending.Countint IEnumerable<Todo>.Count<Todo>()Returns the number of elements in a sequence.Parameterssource — A sequence that contains elements to be counted.ReturnsThe number of elements in the input sequence.ExceptionsArgumentNullException — source is .OverflowException — The number of elements in source is larger than MaxValue.()}");var todos = new List<Todo>
{
new("Learn Glo#", true),
new("Build docs", false),
};
var pending = todos.Where(t => !t.Done);
//^?
// @highlight
Console.WriteLine($"Pending: {pending.Count()}");
// ---cut-start---
/// <summary>A task with a title and completion status.</summary>
public record Todo(string Title, bool Done); Every snippet is compiled by Roslyn. Catch errors in documentation before your readers do.
Full type signatures, XML doc comments, parameter info, and overload counts—just like Visual Studio.
Tooltips use CSS anchor positioning. No JavaScript shipped to your readers—ever.
Place // ^? markers below any token to show its type signature and documentation inline. Readers see exactly what they'd see in their IDE.
varList<int>Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists. itemsList<int>? items = new ListList<int>Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.<intintRepresents a 32-bit signed integer.> { 1, 2, 3 };varintRepresents a 32-bit signed integer. count = itemsList<int>? items.Countint List<int>.CountGets the number of elements contained in the List`1.ReturnsThe number of elements contained in the List`1.;int countvar items = new List<int> { 1, 2, 3 };
var count = items.Count;
// ^? Full extraction of <summary>, <param>, <returns>, <remarks>, and <exception> tags. Rendered in structured, readable popups.
varList<int>Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists. itemsList<int>? items = new List<intintRepresents a 32-bit signed integer.> { 1, 2, 3 };List<int>Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.varintRepresents a 32-bit signed integer. totalint total = itemsList<int>? items.Sumint IEnumerable<int>.Sum()Computes the sum of a sequence of Int32 values.Parameterssource — A sequence of Int32 values to calculate the sum of.ReturnsThe sum of the values in the sequence.ExceptionsArgumentNullException — source is .OverflowException — The sum is larger than MaxValue.();var items = new List<int> { 1, 2, 3 };
// ^?
var total = items.Sum(); Expect specific compiler errors with // @errors: CS1002. Verify error messages and severity. Use // @noErrors to assert clean compilation.
intintRepresents a 32-bit signed integer. xint x = "hello";// @errors: CS0029
int x = "hello"; Assert your snippets compile cleanly with // @noErrors. Catch documentation bugs in CI before your readers find them.
varList<int>Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists. itemsList<int>? items = new ListList<int>Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.<intintRepresents a 32-bit signed integer.> { 1, 2, 3 };varintRepresents a 32-bit signed integer. sumint sum = itemsList<int>? items.Sumint IEnumerable<int>.Sum()Computes the sum of a sequence of Int32 values.Parameterssource — A sequence of Int32 values to calculate the sum of.ReturnsThe sum of the values in the sequence.ExceptionsArgumentNullException — source is .OverflowException — The sum is larger than MaxValue.();ConsoleConsoleRepresents the standard input, output, and error streams for console applications. This class cannot be inherited..WriteLinevoid Console.WriteLine(string? value)Writes the specified string value, followed by the current line terminator, to the standard output stream.Parametersvalue — The value to write.ExceptionsIOException — An I/O error occurred.($"Sum: {sumint sum}");// @noErrors
var items = new List<int> { 1, 2, 3 };
var sum = items.Sum();
Console.WriteLine($"Sum: {sum}"); Highlight, focus, and diff lines with // @highlight, // @focus, and // @diff: +/-. Guide your reader's attention to what matters.
var config = LoadConfig();var conn = config.GetConnection();var db = new DbContext(conn);var config = LoadConfig();
var conn = config.GetConnection();
// @highlight
var db = new DbContext(conn); Extract named #region blocks from full source files. The entire file compiles for accurate types, but only the region appears in output.
public stringstringRepresents text as a sequence of UTF-16 code units. FullNamestring User.FullName => $"{Firststring User.First} {Laststring User.Last}";public class User {
public string First { get; set; }
public string Last { get; set; }
#region FullName
public string FullName
=> $"{First} {Last}";
#endregion
} Hide boilerplate with // ---cut---, // ---cut-before---, // ---cut-after---, or // ---cut-start---/// ---cut-end---. Setup code compiles but doesn't appear in the rendered snippet.
appWebApplication? app.MapGetRouteHandlerBuilder IEndpointRouteBuilder.MapGet(string pattern, Delegate handler)Adds a RouteEndpoint to the IEndpointRouteBuilder that matches HTTP GET requests for the specified pattern.Parametersendpoints — The IEndpointRouteBuilder to add the route to.pattern — The route pattern.handler — The delegate executed when the endpoint is matched.ReturnsA RouteHandlerBuilder that can be used to further customize the endpoint.("/", () => "Hello");appWebApplication? app.Runvoid WebApplication.Run(string? url = null)Runs an application and blocks the calling thread until host shutdown.Parametersurl — The URL to listen to if the server hasn't been configured directly.();#:sdk Microsoft.NET.Sdk.Web
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// ---cut---
app.MapGet("/", () => "Hello");
app.Run(); On .NET 10+, use #:package and #:sdk directives directly in your code. No separate .csproj needed—your snippet is valid C# and Glo# input.
using NewtonsoftNewtonsoft.JsonJson;varstringRepresents text as a sequence of UTF-16 code units. jsonstring? json = JsonConvertJsonConvertProvides methods for converting between .NET types and JSON types..SerializeObjectstring JsonConvert.SerializeObject(object? value)Serializes the specified object to a JSON string.Parametersvalue — The object to serialize.ReturnsA JSON string representation of the object.(new { xint <anonymous type: int x>.x = 1 });#:package Newtonsoft.Json@13.0.3
using Newtonsoft.Json;
var json = JsonConvert.SerializeObject(new { x = 1 }); In-process compilation context cache plus SHA256-keyed disk cache. Rebuilds are fast. Atomic writes handle concurrent processes safely.
$ glosharp verify samples/ --cache-dir .glosharp-cache✓ 24 files verified (18 cached) Completed in 1.2sGlo# runs at build time. Your readers never download extra JavaScript.
Add // ^? markers to show hover info, // @errors to assert compiler errors, and directives like // @highlight to annotate visually.
Glo# invokes the Roslyn compiler, resolves symbols, extracts type signatures, XML docs, and diagnostics. Everything is output as structured JSON.
Use the Shiki transformer, Expressive Code plugin, or standalone HTML renderer. Hovers become CSS-positioned popups. No JavaScript required.
First-class integrations for the most popular documentation tools.
@glosharp/shiki
Drop into any Shiki-powered pipeline. Works with Astro, VitePress, and any framework that uses Shiki for syntax highlighting.
import { transformerGloSharp } from '@glosharp/shiki'
const html = await codeToHtml(code, { lang: 'csharp', transformers: [transformerGloSharp({ project: './My.csproj' })]})@glosharp/expressive-code
Full Expressive Code integration with auto-hover extraction. Every C# block gets rich tooltips automatically. Perfect for Starlight docs.
import { pluginGloSharp } from '@glosharp/expressive-code'
export default defineConfig({ integrations: [starlight({ expressiveCode: { plugins: [pluginGloSharp({ project: './My.csproj' })] } })]})glosharp CLI
Generate self-contained HTML with no external dependencies. Perfect for Hugo, Jekyll, or any static site. Just embed the output.
$ glosharp render snippet.cs \ --theme github-dark \ --standalone \ --output snippet.html@glosharp/core
Programmatic access for custom integrations. Full TypeScript types. Build your own rendering pipeline or IDE extension.
import { createGloSharp } from '@glosharp/core'
const glosharp = createGloSharp({ project: './My.csproj'})const result = await glosharp.process({ code: 'var x = 42; // ^?'})Pick the integration that fits your workflow.
dotnet tool install --global GloSharp.Clinpm install @glosharp/shikiimport { transformerGloSharp } from '@glosharp/shiki'
export default defineConfig({ markdown: { shikiConfig: { transformers: [transformerGloSharp({ project: './samples/Samples.csproj' })] } }})```csharpvar greeting = "Hello, world!";greeting.Length;// ^?```dotnet tool install --global GloSharp.Clinpm install @glosharp/expressive-codeimport { pluginGloSharp } from '@glosharp/expressive-code'
export default defineConfig({ integrations: [starlight({ expressiveCode: { plugins: [pluginGloSharp({ project: './samples/Samples.csproj' })] } })]})With auto-hover extraction, all C# blocks get rich tooltips without any markers. Add // ^? for persistent, always-visible hovers.
dotnet tool install --global GloSharp.Cli# Output JSON with type info, hovers, errorsglosharp process snippet.cs --project ./My.csproj
# Generate standalone HTMLglosharp render snippet.cs --theme github-dark --standalone
# Process from stdinecho 'var x = 42; // ^?' | glosharp process --stdin
# Scaffold a config fileglosharp initdotnet tool install --global GloSharp.Cli# Fail the build if any snippet has unexpected errorsglosharp verify samples/ --project ./Samples.csproj
# With caching for faster CI runsglosharp verify samples/ --cache-dir .glosharp-cacheUse // @errors: CS0029 to mark expected errors and // @noErrors to assert clean compilation. Unexpected errors will fail the build.
The full set of markers you can use in your C# snippets.
// ^? Show type/hover info at this column// ^| Show IntelliSense completions at this column// @errors: CS1002 Assert specific compiler errors are expected// @noErrors Assert the snippet compiles cleanly// @suppressErrors Suppress all or specific error codes// @highlight Highlight this line (or a range)// @focus Focus on this line, dim others// @diff: + Mark as added line in a diff view// @diff: - Mark as removed line in a diff view// ---cut--- Hide everything above this line// ---cut-before--- Same as ---cut--- (long form)// ---cut-after--- Hide everything below this line// ---cut-start--- / // ---cut-end--- Hide a section of code// @nullable: enable Set nullable context// @langVersion: 12 Set C# language version#:package Newtonsoft.Json Declare a NuGet package#:sdk Microsoft.NET.Sdk.Web Set the SDK type#:property Key=Value Set project propertiesGlo# is open source and ready to use today.