RichTextConverter 0.0.1

dotnet add package RichTextConverter --version 0.0.1
                    
NuGet\Install-Package RichTextConverter -Version 0.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="RichTextConverter" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RichTextConverter" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="RichTextConverter" />
                    
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 RichTextConverter --version 0.0.1
                    
#r "nuget: RichTextConverter, 0.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.
#:package RichTextConverter@0.0.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=RichTextConverter&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=RichTextConverter&version=0.0.1
                    
Install as a Cake Tool

RichTextConverter .NET Core

  • RichTextConverter .NET Core, support for converting HTML rich text to Unity TMP rich text.
  • Test using HTML rich text output by wangEditor.

Usage

You can use the RichTextConverter with or without custom node(tag) handler:

// custom node handler, can be a new node handler or override an already implemented node handler
public class TestNodeHandler : INodeHandler
{
    public HtmlNode Handle(HtmlNode node, HtmlDocument doc)
    {
        return node.UnWrap();
    }
}

var richText = "<test>test custom handler</test><h1>大标题</h1><h2>二级标题</h2><div>换行文本1</div><p><h3 style=\"color: rgb(225, 60, 57)\">换行文本2</h3></p><div><a href=\"www.google.com\"><span style=\"color: rgb(235, 144, 58); background-color: rgb(125, 125, 225);\">谷歌链接</span></a></div><br><h4 style=\"text-align: center\">center</h4><p style=\"text-align: start\">start</p>";
var richTextConverter = new RichTextConverter().AddNodeHandlers(new List<KeyValuePair<string, INodeHandler>>{new("test", new TestNodeHandler())});
// the second parameter is used to determine whether it is a RTL language
var unityRichText = richTextConverter.ConvertToUnityRichText(richText, "zh-CN");
Assert.Equal("test custom handler<size=2em><b>大标题</b></size=2em>\n<size=1.5em><b>二级标题</b></size=1.5em>\n换行文本1\n\n<#e13c39><size=1.2em><b>换行文本2</b></size=1.2em>\n</color><#1677ff><crlink=\"www.google.com\"><#eb903a><mark=#7d7de180>谷歌链接</mark=#7d7de180></color></crlink=\"www.google.com\"></color>\n\n<align=center><size=1em><b>center</b></size=1em>\n</align=center><align=left>start\n</align=left>",
    unityRichText);

In ASP.NET Core:

<ItemGroup>
    <PackageReference Include="RichTextConverter" Version="0.0.1" />
</ItemGroup>
services.AddRichTextConverter();
public class YourService
{
    private readonly RichTextConverter _richTextConverter;
    public YourService(RichTextConverter richTextConverter)
    {
        _richTextConverter = richTextConverter;
    }
    
    public string YourMethod()
    {
        var originHtmlText = "<h1>RichTextConverter</h1>";
        return _richTextConverter.ConvertToUnityRichText(originHtmlText, "zh");
    }
}
Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.1 233 2/7/2024