Trix: Clarify How to Get HTML from Document

Created on 12 Oct 2018  路  1Comment  路  Source: basecamp/trix

I really appreciate your timely help with all these issues/questions. Sorry for another one here...

I am a little confused about how to get the HTML document from the editor.

In issue #555 I mentioned how I was getting it using ref in React, but this is not always working well. (Sometimes returns blank after adding attachments or doing other things).

I understand how to get an instance of the document from the editor

const editor = document.querySelector("trix-editor").editor;
const fileContent = editor.getDocument();

and this returns an object like this

{id: 3641, blockList: i(1)}

I can also get the plain text from the document by doing this:

fileContent.toString();

But how do I get a string with the html of the document using editor.getDocument() ?

Most helpful comment

Use element.value to get the HTML string.

>All comments

Use element.value to get the HTML string.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lcsqlpete picture lcsqlpete  路  3Comments

atuttle picture atuttle  路  4Comments

WhatFreshHellIsThis picture WhatFreshHellIsThis  路  4Comments

souporserious picture souporserious  路  4Comments

adueck picture adueck  路  3Comments