This is a tool for converting Draft.js raw ContentState to HTML. It can be usefull for .NET applications when it is needed to store data, generated by Draft.js-based editor and render it to HTML pages on server side.
var exporter = new Exporter();
var html = exporter.Render(
@"
{
""blocks"": [
{
""key"": ""w3rt5"",
""text"": ""Title"",
""type"": ""header-one"",
""depth"": 0,
""inlineStyleRanges"": [],
""entityRanges"": [],
""data"": {}
}
]
}
");
// Returns:
// <h1>
// Title
// </h1>
You can pass custom ExporterConfig object to change render settings.
var exporter = new Exporter(new ExporterConfig
{
EntityDecorators = new Dictionary<string, Func<IReadOnlyDictionary<string, string>, Element>>
{
{"LINK", pairs => new Element("a", pairs, null, true)}
}
});
var exporter = new Exporter(new ExporterConfig
{
StyleMap = new StyleMap
{
Bold = "b"
}
});
var exporter = new Exporter(new ExporterConfig
{
BlockMap = new BlockMap
{
Unstyled = "p"
}
});