ConsoleInk.Net
0.1.7
dotnet add package ConsoleInk.Net --version 0.1.7
NuGet\Install-Package ConsoleInk.Net -Version 0.1.7
<PackageReference Include="ConsoleInk.Net" Version="0.1.7" />
<PackageVersion Include="ConsoleInk.Net" Version="0.1.7" />
<PackageReference Include="ConsoleInk.Net" />
paket add ConsoleInk.Net --version 0.1.7
#r "nuget: ConsoleInk.Net, 0.1.7"
#:package ConsoleInk.Net@0.1.7
#addin nuget:?package=ConsoleInk.Net&version=0.1.7
#tool nuget:?package=ConsoleInk.Net&version=0.1.7
ConsoleInk.NET
ConsoleInk.NET is a lightweight, zero-dependency .NET library for rendering Markdown text directly into ANSI-formatted output suitable for modern console applications, PowerShell, and CI environments. It focuses on streaming processing, enabling efficient rendering of Markdown content as it arrives.
- Targets: .NET Standard 2.0 (C# 10.0 features required)
- NuGet Package: ConsoleInk.Net
- PowerShell Module: Included (
ConsoleInk) for native PowerShell cmdlets - Latest Version: 0.1.4
- Compatible with: .NET Core, .NET Framework, PowerShell 7+, Windows PowerShell 5.1+
Features
- Streaming Markdown Processing: Renders Markdown incrementally, perfect for real-time display.
- Zero External Dependencies: Relies only on the .NET Base Class Library (BCL).
- ANSI Formatting: Outputs text with ANSI escape codes for colors and styles (bold, italic, underline, strikethrough).
- CommonMark & GFM Support: Handles standard Markdown syntax including headings, lists (ordered, unordered, task lists), code blocks (indented and fenced), blockquotes, links (inline, reference*), images (inline alt text), and emphasis. Basic GFM table support is included. (Reference links render literally if definition appears after usage due to streaming nature).
- Theming: Configurable themes (
Default,Monochrome, or custom) to control output appearance. - HTML Stripping: Removes HTML tags from the output by default.
- Word Wrapping: Automatically wraps text to fit the specified console width.
- .NET Library & PowerShell Usage: Provides a C# library (
ConsoleInk.Net) and can be used directly from PowerShell. - Hyperlinks: Supports true OSC-8 hyperlinks in terminal emulators that support them, with fallback to styled text rendering.
- Code Blocks: Handles both indented and fenced code blocks with proper line preservation, indentation control, and syntax-highlighting style.
Feature Details
Hyperlinks
ConsoleInk.NET supports two styles of hyperlink rendering:
- True Hyperlinks (OSC-8): When
UseHyperlinks = true(default) and the terminal supports it, clickable links are rendered using the OSC-8 ANSI escape sequence standard. - Styled Text Fallback: When
UseHyperlinks = falseor in terminals without hyperlink support, links are rendered with styled text showing the URL in parentheses.
var options = new MarkdownRenderOptions
{
UseHyperlinks = true, // Enable true hyperlinks (default)
Theme = new ConsoleTheme
{
LinkTextStyle = Ansi.Underline + Ansi.FgBrightBlue, // Customize link text appearance
LinkUrlStyle = Ansi.FgBrightCyan // Customize URL text appearance (when not using hyperlinks)
}
};
// Render markdown with hyperlinks
string markdown = "Visit [GitHub](https://github.com/) for more info.";
MarkdownConsole.Render(markdown, Console.Out, options);
Code Blocks
ConsoleInk.NET supports both indented and fenced code blocks with careful handling of line breaks:
- Indented Code Blocks: Code indented with 4 spaces or a tab.
- Fenced Code Blocks: Code surrounded by triple backticks (```), optionally specifying a language.
Code blocks preserve line breaks, maintain indentation within the block as written in the original markdown, and are rendered with optional syntax highlighting styles.
var options = new MarkdownRenderOptions
{
Theme = new ConsoleTheme
{
CodeBlockStyle = Ansi.FgBrightBlack // Light gray code blocks
}
};
// Example with fenced code block
string markdown = """
# Code Example
```csharp
// This code will be rendered with proper indentation
if (condition)
{
Console.WriteLine("Indented line");
}
Regular text continues after the code block. """;
MarkdownConsole.Render(markdown, Console.Out, options);
## Installation
You can install the library via NuGet.
### NuGet Package Manager
```powershell
Install-Package ConsoleInk.Net -Version 0.1.4 # Adjust version if needed
.NET CLI
dotnet add package ConsoleInk.Net --version 0.1.4 # Adjust version if needed
PowerShell Module (ConsoleInk)
A native PowerShell module is included! Use the ConvertTo-Markdown cmdlet for Markdown rendering directly in the console, with full support for pipeline input, file input, themes, width, color options, and hyperlinks.
All debugging logs and manual type checks have been removed—the module now provides clean, user-friendly output. If Import-Module succeeds, all cmdlets will work as shown in the demo. Troubleshooting is only needed if you see a true error message.
PowerShell Module Quick Start
Install from PowerShell Gallery:
Install-Module -Name ConsoleInk -Scope CurrentUser
Import the module:
Import-Module ConsoleInk
Render Markdown from a string:
'## Hello from ConsoleInk!' | ConvertTo-Markdown
Render Markdown from a file:
ConvertTo-Markdown -Path ./README.md
Customize output:
'## Monochrome' | ConvertTo-Markdown -Theme Monochrome
'## No Color' | ConvertTo-Markdown -NoColor
'## Custom Width' | ConvertTo-Markdown -Width 100
Pipeline usage:
Get-Content ./README.md | ConvertTo-Markdown
See samples/PowerShell/Demo-Module-PSGallery.ps1 for a comprehensive, feature-rich example covering:
- Pipeline input
- File input
- Theme selection (Default/Monochrome)
- Width selection
- Hyperlink rendering (OSC 8)
- Error handling
Cmdlet:
ConvertTo-Markdown
Supports pipeline and file input, width, theme selection, color toggling, and hyperlinks. See the Demo-Module.ps1 for a full-featured demonstration.
Tip: The .NET namespace for all types is ConsoleInk (e.g., [ConsoleInk.MarkdownRenderOptions]).
Usage
C# Library (ConsoleInk.Net)
Add a reference to the ConsoleInk.Net package or project.
See the src/ConsoleInk.Demo project for a runnable example.
using ConsoleInk.Net; // Namespace is ConsoleInk
using System.IO;
// --- Batch Rendering ---
string markdown = """
# Hello Console!
This is **ConsoleInk.NET**.
* Renders Markdown
* Uses *ANSI* codes
""";
// Configure options (optional)
var options = new MarkdownRenderOptions
{
ConsoleWidth = 100,
Theme = ConsoleTheme.Default
};
// Render to a string
string ansiOutput = MarkdownConsole.Render(markdown, options);
Console.WriteLine(ansiOutput);
// Render directly to the console
MarkdownConsole.Render(markdown, Console.Out, options);
// --- Streaming Rendering ---
var inputStream = new StringReader("## Streaming Demo\nContent arrives piece by piece...");
// Use the writer within a 'using' block for automatic disposal and completion
using (var writer = new MarkdownConsoleWriter(Console.Out, options))
{
char[] buffer = new char[50];
int bytesRead;
while ((bytesRead = inputStream.Read(buffer, 0, buffer.Length)) > 0)
{
writer.Write(buffer, 0, bytesRead);
// writer.Flush(); // Optional: Flush periodically if needed
System.Threading.Thread.Sleep(100); // Simulate delay
}
// writer.Complete(); // No longer needed! Dispose called implicitly by 'using'.
}
To run the included C# demo:
dotnet run --project src/ConsoleInk.Demo/ConsoleInk.Demo.csproj
PowerShell Usage
Option 1: PowerShell Module (Recommended)
The ConsoleInk PowerShell module provides the ConvertTo-Markdown cmdlet for rendering Markdown directly in the console, with full support for pipeline input, file input, themes, width, color options, and hyperlinks.
Install from PowerShell Gallery:
Install-Module -Name ConsoleInk -Scope CurrentUser
Import the module:
Import-Module ConsoleInk
Render Markdown from a string:
'## Hello from ConsoleInk!' | ConvertTo-Markdown
Render Markdown from a file:
ConvertTo-Markdown -Path ./README.md
Customize output:
'## Monochrome' | ConvertTo-Markdown -Theme Monochrome
'## No Color' | ConvertTo-Markdown -NoColor
'## Custom Width' | ConvertTo-Markdown -Width 100
Pipeline usage:
Get-Content ./README.md | ConvertTo-Markdown
For a comprehensive, feature-rich example, see Demo-Module-PSGallery.ps1, which covers:
- Pipeline input
- File input
- Theme selection (Default/Monochrome)
- Width selection
- Hyperlink rendering (OSC 8)
- Error handling
Option 2: Direct DLL Loading
You can also use ConsoleInk.Net directly from PowerShell by loading the compiled DLL. See samples/PowerShell/Demo.ps1 for a working example.
Steps:
- Build the Library: Ensure
ConsoleInk.Net.dllexists (e.g., rundotnet build src/ConsoleInk.sln). - Run the Script:
pwsh -File ./samples/PowerShell/Demo.ps1
You can specify -LibPath if you want to use a custom build directory.
Building & Testing
Clone the repository:
git clone https://github.com/stimpy77/ConsoleInk.NET.git cd ConsoleInk.NETBuild the library:
# Builds the ConsoleInk.Net library dotnet build src/ConsoleInk.Net/ConsoleInk.Net.csproj- This will compile the
ConsoleInk.Netlibrary. - If building in
Releaseconfiguration (dotnet build src/ConsoleInk.Net/ConsoleInk.Net.csproj -c Release), the NuGet package (.nupkg) and symbols package (.snupkg) will be generated insrc/ConsoleInk.Net/bin/Release/.
- This will compile the
Build the PowerShell module:
# Build and copy DLL to PowerShell module ./build-psmodule.ps1- The PowerShell module requires the ConsoleInk.Net.dll to be copied to
src/powershell-module/ConsoleInk/lib/. - Note: The DLL is not committed to git and must be built locally.
- See
src/powershell-module/README.mdfor more details.
- The PowerShell module requires the ConsoleInk.Net.dll to be copied to
Run tests:
dotnet test src/ConsoleInk.sln
Version Compatibility
- Library: .NET Standard 2.0 (requires C# 10.0 features; ensure your build environment supports this)
- Demo & PowerShell Module: .NET Standard 2.0
- Tests: May target newer .NET for compatibility with latest test SDKs
- PowerShell: Compatible with PowerShell 7+ and Windows PowerShell 5.1 (when run with .NET Standard 2.0 DLL)
Release Notes
- 0.1.6 (2025-10-26):
- Fixed hyperlinks and inline formatting (bold, italic, strikethrough) not rendering in list items
- Improved PowerShell module build process - DLLs no longer committed to git
- Added
build-psmodule.ps1script for streamlined PowerShell module builds - Fixed PowerShell Demo.ps1 script issues
- 0.1.4 (2025-06-01):
- Full .NET Standard 2.0 migration for library, demo, and PowerShell module
- PowerShell module (
ConsoleInk) released:ConvertTo-MarkdownandShow-Markdowncmdlets, pipeline/file input, themes, color - All build/test/demo projects updated for compatibility and C# 10.0 features
- Type-mismatch and build errors resolved for .NET Standard
- Documentation updated for new module and usage
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.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.
v0.1.7: Fixed word-wrap to use visible character width (excluding ANSI escape sequences) so styled paragraphs no longer wrap short.