Copy and paste with formatting
ExtractFragment copies a span's content, formatting, styles and lists included, into a DocumentFragment; InsertFragment puts a fragment in at a position as one undoable DocumentEdit, as Word pastes with the source formatting kept.
The code
using DocWright.Dom;
using DocWright.Dom.Editing;
// Copy " quarterly" (the word bold) and paste it after "Before." in the destination's paragraph.
var word = new DocumentSpan(DocumentPosition.InParagraph(intro, 3), DocumentPosition.InParagraph(intro, 13));
using (DocumentFragment copied = source.ExtractFragment(word))
{
DocumentEdit paste = destination.InsertFragment(DocumentPosition.InParagraph(target, 7), copied);
Console.WriteLine($"pasted inline; the caret is now at offset {paste.After.Offset}");
}
// Copy the heading with its mark (the span ends at the next paragraph's start): it comes with its style.
List<Paragraph> lines = source.Sections[0].Blocks.OfType<Paragraph>().ToList();
var whole = new DocumentSpan(DocumentPosition.StartOf(lines[1]), DocumentPosition.StartOf(lines[2]));
using (DocumentFragment copied = source.ExtractFragment(whole))
{
Console.WriteLine($"ends with a paragraph mark: {copied.EndsWithParagraphMark}");
destination.InsertFragment(DocumentPosition.StartOf(target), copied);
}
foreach (Paragraph paragraph in destination.Sections[0].Blocks.OfType<Paragraph>())
{
Console.WriteLine($"{paragraph.Format.StyleId ?? "Normal",-8} {string.Concat(paragraph.Inlines.OfType<TextRun>().Select(r => r.Text))}");
}
Output
pasted inline; the caret is now at offset 17
ends with a paragraph mark: True
Heading1 Results
Normal Before. quarterly After.

The rules
- A paragraph's properties travel with its mark. The destination splits at the position. The fragment's first paragraph joins the text before it, and its style and list win when its mark is part of the fragment; the paragraphs after it go in whole; a last piece without its mark joins the text after the position and takes that paragraph's properties. Content from inside one paragraph simply goes in at the position.
- The mark. A span ending at the start of a paragraph ends with the previous paragraph's mark (
EndsWithParagraphMark); one ending inside a paragraph does not. - Definitions. A fragment carries only what its content uses: styles with their based-on chain, lists, notes, pictures, link targets. A style or list the destination already defines under the same id keeps the destination's definition; the others are added, and undo removes them again. A bookmark name the destination already has is dropped from the pasted copy.
- Other sources.
DocumentFragment.FromDocument(document, endsWithParagraphMark)makes a fragment of any document a reader produced, such as HTML from a clipboard: passfalsefor content that should go into the paragraph at the position.
Moving text is the three edits in a row: ExtractFragment, DeleteRange, InsertFragment. Word's smart cut and paste, which adjusts spaces at a paste's edges, is a user option and is not reproduced.