internal void WrapInlineInParagraph(int nInsertAt, int nChildren) { DocumentNodeArray dna = _converterState.DocumentNodeArray; Debug.Assert(nInsertAt >= 0 && nChildren > 0 && nInsertAt + nChildren - 1 < dna.Count); DocumentNode dnChild = dna.EntryAt(nInsertAt + nChildren - 1); DocumentNode dn = new DocumentNode(DocumentNodeType.dnParagraph); dn.FormatState = new FormatState(dnChild.FormatState); dn.ConstrainFontPropagation(dn.FormatState); DocumentNode dnParent = null; // Parent shouldn't be the child of new inserted document node // to avoid the infinite loop on InsertChildAt() if (dnChild.ClosedParent != null && dnChild.ClosedParent.Index < nInsertAt && dnChild.ClosedParent.Index > (nInsertAt + nChildren - 1)) { dnParent = dnChild.ClosedParent; } dna.InsertChildAt(dnParent, dn, nInsertAt, nChildren); dna.CoalesceOnlyChildren(_converterState, nInsertAt); }
internal void HandleParagraphFromText(FormatState formatState) { DocumentNodeArray dna = _converterState.DocumentNodeArray; DocumentNode dn; // Insert the paragraph before any text or inline nodes at the top of the stack. int nInsertAt = dna.Count; // Default insertion location for (; nInsertAt > 0; nInsertAt--) { dn = dna.EntryAt(nInsertAt - 1); if (!dn.IsInline || (dn.ClosedParent != null && !dn.ClosedParent.IsInline) || !dn.IsMatched) { break; } } dn = new DocumentNode(DocumentNodeType.dnParagraph); dn.FormatState = new FormatState(formatState); dn.ConstrainFontPropagation(formatState); dna.InsertNode(nInsertAt, dn); // Now close immediately. dna.CloseAt(nInsertAt); dna.CoalesceOnlyChildren(_converterState, nInsertAt); }