-
Couldn't load subscription status.
- Fork 44
Description
Brief bug description
When working with rich text as IRichTextContent, only top level <object> and <figure> tags are parsed and converted to their corresponding types:
// part of RichTextContentConverter.GetPropertyValueAsync method
foreach (var block in htmlInput.Body.Children)
{
if (block.TagName?.Equals("object", StringComparison.OrdinalIgnoreCase) == true && block.GetAttribute("type") == "application/kenticocloud" && block.GetAttribute("data-type") == "item")
{
var codename = block.GetAttribute("data-codename");
blocks.Add(new InlineContentItem(await context.GetLinkedItem(codename)));
}
else if (block.TagName?.Equals("figure", StringComparison.OrdinalIgnoreCase) == true)
{
var img = block.Children.FirstOrDefault(child => child.TagName?.Equals("img", StringComparison.OrdinalIgnoreCase) == true);
if (img != null)
{
var assetId = Guid.Parse(img.GetAttribute("data-asset-id"));
blocks.Add(element.Images[assetId]);
}
}
else
{
blocks.Add(new HtmlContent { Html = block.OuterHtml });
// method doesn't recurse, therefore ignoring potential nested <figure> nodes
}
}
return blocks;The above code is part of RichTextContentConverter.GetPropertyValueAsync method, which returns IEnumerable<IRichTextBlock>. IRichTextBlock can be either IHtmlContent (for arbitrary HTML), IInlineContentItem (for linked items and components in rich text) and IInlineImage (assets in rich text).
While linked items and components are always top level in Kontent.ai rich text, assets can be nested in a table. Because the foreach in the aforementioned method processes only top level HTML tags, assets in a table are ignored and therefore cannot be resolved properly.
Using assets in a table cell seems like an edge case, but, ideally, the parser should take even such situations into account. Considering the fix would likely involve modifying existing IHtmlContent structure to be recursive, this might be a breaking change.
Repro steps
- Generate a model with structured rich text approach (
IRichTextContent) - Request an item with a rich text element, containing a table with an asset.
- Observe contents of the element in the mapped response
Expected behavior
Explained above.