ktsu.ImGui.Markdown
3.16.2
Prefix Reserved
dotnet add package ktsu.ImGui.Markdown --version 3.16.2
NuGet\Install-Package ktsu.ImGui.Markdown -Version 3.16.2
<PackageReference Include="ktsu.ImGui.Markdown" Version="3.16.2" />
<PackageVersion Include="ktsu.ImGui.Markdown" Version="3.16.2" />
<PackageReference Include="ktsu.ImGui.Markdown" />
paket add ktsu.ImGui.Markdown --version 3.16.2
#r "nuget: ktsu.ImGui.Markdown, 3.16.2"
#:package ktsu.ImGui.Markdown@3.16.2
#addin nuget:?package=ktsu.ImGui.Markdown&version=3.16.2
#tool nuget:?package=ktsu.ImGui.Markdown&version=3.16.2
ktsu.ImGui.Markdown
ImGui.Markdown renders CommonMark markdown directly inside Dear ImGui, using Markdig for parsing. It is a standalone package with no dependency on ktsu.ImGui.App, so it can be dropped into any Hexa.NET.ImGui application.
Features
- CommonMark parsing: Full CommonMark syntax plus pipe tables, task lists, and autolinks, via a configured Markdig pipeline
- Headings, emphasis, and code: Headings scale from the live font size, so DPI and accessibility scaling are respected automatically; bold and italic fall back to faux styling when no matching font is registered
- Lists: Nested bullet, ordered, and task lists
- Blockquotes and thematic breaks: Rendered with an indent bar and a horizontal rule respectively
- Tables: Rendered with ImGui's native table API
- Links: Clickable, with an optional callback or automatic OS-open for http, https, and mailto schemes
- Images: Local images via a resolver callback; remote or unresolved images fall back to a placeholder box with the alt text
- Two APIs: A cached static
Renderfor convenience, and aMarkdownDocumentinstance for hot render paths where the source is parsed once
Installation
dotnet add package ktsu.ImGui.Markdown
Quick Start
Static render (cached by source)
ImGuiMarkdown.Render parses the given markdown and caches the result keyed by the source string, so calling it every frame with the same text does not re-parse it.
using ktsu.ImGui.Markdown;
using Hexa.NET.ImGui;
ImGui.Begin("Markdown");
ImGuiMarkdown.Render("""
# Hello, ImGui
A **CommonMark** renderer for *Dear ImGui*, with `inline code` and [links](https://github.com/ktsu-dev).
""");
ImGui.End();
MarkdownDocument for hot paths
When the same markdown source is rendered every frame, parse it once into a MarkdownDocument and render that instance instead of relying on the source-keyed cache.
using ktsu.ImGui.Markdown;
private static readonly MarkdownDocument ReadmeDocument = new("""
# Changelog
- Fixed a bug
- Added a feature
""");
// In the render loop:
ReadmeDocument.Render();
Configuration
Pass a MarkdownConfig to either API to control fonts, links, images, and spacing. All members are optional. Without any configuration, the renderer uses faux emphasis styling and image placeholder boxes.
MarkdownConfig config = new()
{
FontResolver = ResolveFont,
OnLinkClicked = url => Log.Info($"Clicked: {url}"),
ImageResolver = ResolveImage,
};
ImGuiMarkdown.Render(markdown, config);
| Option | Type | Description |
|---|---|---|
FontResolver |
Func<MarkdownFontRole, float, ImFontPtr?>? |
Resolves a font for a typographic role (Body, Bold, Italic, BoldItalic, Code, H1-H6) at a target pixel size. Return null for a role to fall back to the current font at that size, with faux bold/italic styling applied for emphasis roles. |
OnLinkClicked |
Action<string>? |
Invoked when a link is clicked. When null, http, https, and mailto links open with the OS default handler; other schemes are ignored. |
ImageResolver |
Func<string, MarkdownImageResult?>? |
Resolves an image source string to a MarkdownImageResult (an ImGui texture ID and a draw size). Return null, or omit the resolver, to draw a placeholder box with the alt text instead. |
HeadingScales |
IReadOnlyList<float> |
Size multipliers applied to the live body font size, H1 first. Defaults to [2.0, 1.6, 1.35, 1.15, 1.0, 0.9]. |
WrapWidth |
float? |
Explicit wrap width in pixels. When null, the available content region width is used. |
ListIndentPixels |
float |
Indentation applied per list nesting level, in pixels. Defaults to 20.0. |
ParagraphSpacingPixels |
float |
Vertical spacing added after paragraphs and blocks, in pixels. Defaults to 6.0. |
LinkColor |
ImGuiVector4? |
Explicit link color. When null, a theme-appropriate color is used. |
Registering real bold and italic fonts
By default, bold text is drawn with a faux technique (a second offset draw call that thickens the glyphs), and italic text renders upright because no shear is applied. For crisper output, register named font variants at startup (for example through ImGuiAppConfig.Fonts) and resolve them per role:
private static ImFontPtr? ResolveFont(MarkdownFontRole role, float pixelSize) => role switch
{
MarkdownFontRole.Bold => boldFont,
MarkdownFontRole.Italic => italicFont,
MarkdownFontRole.BoldItalic => boldItalicFont,
MarkdownFontRole.Code => monoFont,
_ => null, // headings and body text keep the current font at pixelSize
};
Resolving local images
ImageResolver receives the raw source string from the markdown image syntax (for example ) and returns the loaded texture ID and draw size:
private static MarkdownImageResult? ResolveImage(string source)
{
AbsoluteFilePath imagePath = AppContext.BaseDirectory.As<AbsoluteDirectoryPath>() / source.As<FileName>();
if (!File.Exists(imagePath))
{
return null; // falls back to a placeholder box with the alt text
}
ImGuiAppTextureInfo texture = ImGuiApp.GetOrLoadTexture(imagePath);
return new MarkdownImageResult(texture.TextureId, new Vector2(64, 64));
}
Supported CommonMark Elements
- Headings (
#through######) - Paragraphs, with bold (
**) and italic (*) emphasis - Inline code (
`code`) and fenced or indented code blocks - Bullet lists, ordered lists, and task lists (
- [ ]/- [x]), all with nesting - Blockquotes
- Thematic breaks (
---) - Pipe tables
- Links, including autolinks
- Images
v1 Limitations
- No syntax highlighting in code blocks; code is rendered in a plain monospace style
- No asynchronous remote image download; remote or unresolved image sources always show a placeholder box with the alt text
- Raw HTML blocks and inline HTML are rendered as escaped, literal text, not interpreted
- Faux italic renders upright when no italic font is supplied through
FontResolver, since no glyph shear is applied
Demo
See examples/ImGuiMarkdownDemo/ for a runnable demo covering headings, emphasis, lists, quotes, code, tables, and images.
dotnet run --project examples/ImGuiMarkdownDemo
Contributing
Contributions are welcome! For feature requests, bug reports, or questions, please open an issue on the GitHub repository. If you would like to contribute code, please open a pull request with your changes.
License
ImGui.Markdown is licensed under the MIT License. See LICENSE for more information.
| 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
- Hexa.NET.ImGui (>= 2.2.9)
- ktsu.ImGui.Color (>= 3.16.2)
- ktsu.Semantics.Color (>= 3.2.0)
- Markdig (>= 1.3.2)
-
net8.0
- Hexa.NET.ImGui (>= 2.2.9)
- ktsu.ImGui.Color (>= 3.16.2)
- ktsu.Semantics.Color (>= 3.2.0)
- Markdig (>= 1.3.2)
-
net9.0
- Hexa.NET.ImGui (>= 2.2.9)
- ktsu.ImGui.Color (>= 3.16.2)
- ktsu.Semantics.Color (>= 3.2.0)
- Markdig (>= 1.3.2)
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 |
|---|---|---|
| 3.16.2 | 42 | 8/28/2026 |
| 3.16.1 | 42 | 8/28/2026 |
| 3.16.0 | 43 | 8/28/2026 |
| 3.15.1 | 52 | 8/28/2026 |
| 3.15.0 | 45 | 8/27/2026 |
| 3.14.1 | 51 | 8/27/2026 |
| 3.14.0 | 51 | 8/26/2026 |
| 3.13.2 | 55 | 8/26/2026 |
| 3.13.1 | 74 | 8/26/2026 |
| 3.13.0 | 70 | 8/26/2026 |
| 3.12.1 | 76 | 8/25/2026 |
| 3.12.0 | 83 | 8/25/2026 |
| 3.11.1 | 89 | 8/25/2026 |
| 3.11.0 | 92 | 8/24/2026 |
| 3.10.0 | 106 | 8/21/2026 |
| 3.9.3 | 91 | 8/20/2026 |
| 3.9.2 | 104 | 8/20/2026 |
| 3.9.1 | 101 | 8/19/2026 |
| 3.9.0 | 103 | 8/19/2026 |
| 3.8.1 | 67 | 8/19/2026 |
## v3.16.2 (patch)
Changes since v3.16.1:
- Bump the ktsu group with 3 updates ([@dependabot[bot]](https://github.com/dependabot[bot]))