Paste from Word in an ASP.NET Core rich text editor

People write in Word and then paste it into your site. Unfiltered, that brings pages of hidden markup, fonts you do not use and sizes that break your layout. RichTextBox cleans it as it arrives and keeps what matters.
The setting
Pasting from Word is handled by default. To say so explicitly, set the mode:
<richtextbox name="Body"
toolbar="default"
height="400px"
paste-mode="Word"></richtextbox>
paste-mode | What it does |
|---|---|
Auto | Decides from what was pasted |
Word | Cleans Word's markup, keeps the structure |
Text | Keeps only the text |
Disabled | Turns pasting off |
What survives
- Headings, bold, italic and links.
- Numbered and bulleted lists, including nesting.
- Tables.
- Pictures, which can go to your server through the normal upload path.
What goes
Word's own XML and conditional comments, the long mso- style rules, empty paragraphs and the like. You get back HTML a person could read.
Pasted pictures obey your rules
A picture pasted into the editor is uploaded like any other, so your size limit, allowed types and metadata removal all apply. If people's pictures fail to paste, the 4 MB default is the first thing to check.
Still clean it on the server
Paste cleaning happens in the browser for people using your page. It says nothing about a request sent some other way, so keep [RichTextHtml] on the property that receives the content.
Whole documents
For a full document, importing a .docx file is a better path than copy and paste. Add the importdocument button to your toolbar, and the server also has POST /richtextbox/import/docx. For the other direction, see export to Word.