ConsoleInk.Net 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ConsoleInk.Net --version 0.1.1
                    
NuGet\Install-Package ConsoleInk.Net -Version 0.1.1
                    
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="ConsoleInk.Net" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConsoleInk.Net" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="ConsoleInk.Net" />
                    
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 ConsoleInk.Net --version 0.1.1
                    
#r "nuget: ConsoleInk.Net, 0.1.1"
                    
#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 ConsoleInk.Net@0.1.1
                    
#: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=ConsoleInk.Net&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=ConsoleInk.Net&version=0.1.1
                    
Install as a Cake Tool

ConsoleInk.NET

Build Status NuGet License

ConsoleInk.NET is a lightweight, zero-dependency .NET library for rendering Markdown text directly into ANSI-formatted output suitable for modern console applications. It focuses on streaming processing, enabling efficient rendering of Markdown content as it arrives.

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), 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.

Installation

You can install the library via NuGet.

NuGet Package Manager

Install-Package ConsoleInk.Net -Version 0.1.1 # Adjust version if needed

.NET CLI

dotnet add package ConsoleInk.Net --version 0.1.1 # Adjust version if needed

(A dedicated PowerShell module ConsoleInk.PowerShell is planned but not yet available.)

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 (Direct DLL Loading)

The library can be used directly from PowerShell by loading the compiled DLL. See the samples/PowerShell/Demo.ps1 script for a working example.

Steps:

  1. Build the Library: Ensure ConsoleInk.Net.dll exists (e.g., run dotnet build src/ConsoleInk.sln).
  2. Run the Script:
# Navigate to the repository root or adjust paths in the script

# Using default Debug build path:
pwsh -File ./samples/PowerShell/Demo.ps1

# If you built in Release configuration:
pwsh -File ./samples/PowerShell/Demo.ps1 -LibPath '../src/ConsoleInk.Net/bin/Release/net9.0'

(A dedicated ConsoleInk.PowerShell module with cmdlets like ConvertTo-ConsoleMarkdown and Show-Markdown is planned for easier PowerShell integration.)

Building & Testing

  1. Clone the repository:

    git clone https://github.com/stimpy77/ConsoleInk.NET.git
    cd ConsoleInk.NET
    
  2. Build the solution (including Library, Demo, and Tests):

    # Builds all projects referenced by the solution
    dotnet build src/ConsoleInk.sln
    
    • This will compile the ConsoleInk.Net library.
    • If building in Release configuration (dotnet build src/ConsoleInk.sln -c Release), the NuGet package (.nupkg) and symbols package (.snupkg) will be generated in src/ConsoleInk.Net/bin/Release/.
  3. Run tests:

    dotnet test src/ConsoleInk.sln
    

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 Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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
0.1.4 346 6/1/2025
0.1.3 98 6/1/2025
0.1.2 147 4/13/2025
0.1.1 138 4/13/2025
0.1.0 172 4/9/2025

Initial release.