private void WriteFragments(HtmlFragment fragment, DocumentContainer parentContainer) { if (parentContainer != null) { foreach (var childFragment in fragment.Fragments) { var writer = HtmlWriterFactory.Find(childFragment); var ctrl = writer?.GetControl(childFragment); if (ctrl != null) { if (!parentContainer.CanContain(ctrl)) { var antecesorContainer = parentContainer.Find(ctrl); if (antecesorContainer == null) { continue; } else { parentContainer = antecesorContainer; } } var currentContainer = parentContainer.Append(ctrl); WriteFragments(childFragment, currentContainer); writer?.ApplyStyles(_docStyles, ctrl, childFragment); } } } }