···241241 }
242242 },
243243 },
244244- content: generateJSON(richtext.text.toString(), extensions, {
244244+ content: generateJSON(richTextToHTML(richtext), extensions, {
245245 preserveWhitespace: 'full',
246246 }),
247247 autofocus: 'end',
···380380 )}
381381 </>
382382 )
383383+}
384384+385385+/**
386386+ * Helper function to initialise the editor with RichText, which expects HTML
387387+ *
388388+ * All the extensions are able to initialise themselves from plain text, *except*
389389+ * for the Mention extension - we need to manually convert it into a `<span>` element
390390+ *
391391+ * It also escapes HTML characters
392392+ */
393393+function richTextToHTML(richtext: RichText): string {
394394+ let html = ''
395395+396396+ for (const segment of richtext.segments()) {
397397+ if (segment.mention) {
398398+ html += `<span data-type="mention" data-id="${escapeHTML(segment.mention.did)}"></span>`
399399+ } else {
400400+ html += escapeHTML(segment.text)
401401+ }
402402+ }
403403+404404+ return html
405405+}
406406+407407+function escapeHTML(str: string): string {
408408+ return str
409409+ .replace(/&/g, '&')
410410+ .replace(/</g, '<')
411411+ .replace(/>/g, '>')
412412+ .replace(/"/g, '"')
383413}
384414385415function editorJsonToText(