RichText in Contentful is deserialized to Document type, and Document is converted to MarkupString type for use. (I created an extension method). When using the "code" tag in Contentful's RichTextEditor, the "pre" tag does not exist in the parent element, so line breaks and indentation are ignored by the browser.
Is there a way to add a parent element to any HTML tag?
public static MarkupString ToHtml(this Document doc)
{
var renderer = new HtmlRenderer();
var html = renderer.ToHtml(doc).GetAwaiter().GetResult();
return (MarkupString)html;
}
using Blazor ServerSide.
<div>
@entry.Content.ToHtml()
</div>
Model
public class ContentfulEntry
{
public SystemProperties Sys { get; set; }
public string Title { get; set; }
public Document Content { get; set; }
public string Description { get; set; }
public Asset Cover { get; set; }
}