When you paste a table in the Editor or insert one through the InsertHTML tool, the Editor adds two <tbody> tags making this invalid HTML.
If you include a table in the initially rendered content (not pasting it afterwards), two <tbody> tags appear as well.
If you create table using the Create Table tool this behavior is not present, only one <tbody> tag is added as expected.
Hello all,
Here is a workaround that you can use until the bug is fixed:
Razor
@using Telerik.Blazor.Components.Editor
@inject IJSRuntime jsRuntime
<TelerikEditor Tools="@EditorToolSets.All"
Height="300px" Id="editor1"
Value="@Value" ValueChanged="@StripTBODY"></TelerikEditor>
@code {
public string Value = @"<table class=""k-table""><tbody><tr><td><p><br></p></td></tr></tbody></table>";
async Task StripTBODY(string newValue)
{
var processedValue = newValue;
foreach (var fix in EditorTBodyFixes)
{
processedValue = processedValue.Replace(fix.Key, fix.Value);
}
Value = processedValue;
if (processedValue != newValue)
{
await jsRuntime.InvokeAsync<string>("removetbody", "editor1");
}
}
Dictionary<string, string> EditorTBodyFixes = new Dictionary<string, string>() {
{ "<tbody><tbody>", "<tbody>" },
{ "</tbody></tbody>", "</tbody>" },
{ "<tbody><tr></tr></tbody>", "" }
};
protected override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
jsRuntime.InvokeAsync<string>("removetbody", "editor1");
}
return base.OnAfterRenderAsync(firstRender);
}
}
JavaScript
window.removetbody = (id) => {
window.setTimeout(function () {
var iframe = document.querySelector("#" + id + " iframe");
if (iframe) {
var tbodies = iframe.contentWindow.document.querySelectorAll("table > tbody > tbody");
if (tbodies.length > 0) {
tbodies.forEach(function (tbodyElement) {
tbodyElement.parentElement.innerHTML = tbodyElement.innerHTML;
});
}
}
}, 1000);
}
Regards,
Dimo
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.