Sander.txt2html 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sander.txt2html --version 2.0.1
NuGet\Install-Package Sander.txt2html -Version 2.0.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="Sander.txt2html" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sander.txt2html --version 2.0.1
#r "nuget: Sander.txt2html, 2.0.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.
// Install Sander.txt2html as a Cake Addin
#addin nuget:?package=Sander.txt2html&version=2.0.1

// Install Sander.txt2html as a Cake Tool
#tool nuget:?package=Sander.txt2html&version=2.0.1

GitHub license NetStandard 2.0

Introduction

Use txt2html to convert plain text files to the hypertext markup language (HTML).

Features:

  • Clean and compliant HTML5
  • Option to include your own CSS
  • HTML entity replacement (optional; you can also edit the entity list). Note that critical entities (<,>,",&) are always replaced, so generally you don't have to enable this option
  • Detects and fixes _italic_ and *bold* (optional)
  • Detects and marks URL's (optional)
  • Supports specifying encoding
  • Optional paragraph joining. Attempts to merge hard-coded line-breaks into coherent paragraphs. Lines shorter than specified length, which don't end with characters marking end of line ('.?!") are joined.
  • Fast (v2 is more than 50x faster than v1!)
  • Free and open source
  • .NET Standard 2.0, meaning txt2html can be used with .NET Framework 4.6.1+, .NET Core 2.0 and more - see here for detailed information.

Examples

Full example

var conversionSettings = new ConversionSettings()
	{ DetectUrls = true, FixBold = true, FixItalic = true, MinimumLineLength = 50, Title = "Lorem Ipsum"};

var text = new[]
	{
	"Lorem ipsum dolor sit amet,",
	"consectetur adipiscing elit. ",
	"Haec quo *modo* _conveniant_, non sane intellego.",
	"Sed virtutem ipsam inchoavit, nihil amplius. ",
	"",
	"Non dolere, inquam, istud quam vim habeat postea videro; ",
	"Duo Reges: constructio interrete. www.example.com. ",
	"Sed quid sentiat, non videtis. At iste non dolendi status non vocatur voluptas."
	};

var result = Converter.Convert(conversionSettings, text.ToList());

Methods

All described methods have async counterparts, with method name being ConvertAsync() instead of Convert().

//Using existing strings (IEnumerable<string>)
var result = Converter.Convert(settings, content);
//Specify the file to use as source, optionally specifying encoding (if omitted, .NET will attempt to auto-detect the encoding
var result = Converter.Convert(settings, @"d:\texts\Shakespeare.txt", Encoding.ASCII);
//Specify file stream to use as a source, and optional encoding. It is up to the caller to set the proper position in the file
//FileStream is not disposed.
FileStream fs = File.OpenRead(@"d:\texts\Shakespeare.txt");
fs.Position = 42;
var result = Converter.Convert(settings, fs, Encoding.Unicode);
//Convert text from stream reader
//Neither StreamReader nor base stream is disposed
StreamReader sr = new StreamReader(@"d:\texts\Shakespeare.txt")
var result = Converter.Convert(settings, sr);

Conversion settings

ConversionSettings.cs allows you to control various settings for text conversion.

  • bool FixBold: Set to true to wrap the text between *asterisks* with <strong>. Defaults to false.
  • bool FixItalic: Set to true to wrap the text between _underscores_ with <em>. Defaults to false.
  • bool DetectUrls: Detect and mark URLs. All www, http, https, ftp, news and file protocols/markers are supported.
  • uint? MinimumLineLength: Minimum line length to use for paragraph joining. Lines shorter than specified length, which don't end with characters marking end of line ('.?!") are joined. Defaults to null (joining disabled)
  • bool CreateEntities: Set to true to HTML entity replacement. Change txt2html.ent to specify what is changed. Note that critical entities (> < " &) are always replaced. If you don't include entities file (txt2html.ent), txt2html uses the embedded default entities list. Defaults to false
  • string Css: Include custom CSS to the conversion result. String should contain the actual CSS, not file path. Defaults to null (no special CSS)
  • string Title: Set the HTML title for conversion. Defaults to null (no title)
Product 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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last updated
2.0.2 193 6/29/2023
2.0.1 1,012 9/19/2018