nhi / portable-text-dotnet

Convert HTML into PortableText in .NET (C#) https://www.nuget.org/packages/NHI.PortableText

Home Page:https://portabletext-frontend-nhi.azurewebsites.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NHI.PortableText

NHI.PortableText is a .NET Standard 2.0 library for converting HTML to PortableText. The implementation creates PortableText which adheres to the v.0.0.1 working draft specification, and tries to be compliant with existing tooling which deviate from the specification. The library is extendable by adding custom parsers for HTML elements which need to be handled in a project-specific or otherwise non-standard fashion.

The library uses HtmlAgilityPack to parse HTML elements and Json.Net to serialize the internal models to PortableText.

Quickstart

Example:

var bc = new BlockConverter();
var portableText = bc.SerializeHtml("<p>Welcome to <b>PortableText</b></p>");
Console.WriteLine(portableText);

Output:

[
  {
    "_type": "block",
    "_key": "5E33484E",
    "markDefs": [],
    "style": "normal",
    "level": null,
    "listItem": null,
    "children": [
      {
        "_type": "span",
        "_key": "C3B531D",
        "marks": [],
        "text": "Welcome to "
      },
      {
        "_type": "span",
        "_key": "2767C23D",
        "marks": [
          "strong"
        ],
        "text": "PortableText"
      }
    ]
  }
]

For further information on usage, see the package README

About

Convert HTML into PortableText in .NET (C#) https://www.nuget.org/packages/NHI.PortableText

https://portabletext-frontend-nhi.azurewebsites.net

License:MIT License


Languages

Language:C# 91.0%Language:JavaScript 4.8%Language:HTML 2.8%Language:CSS 1.3%Language:Shell 0.1%