Class RichTextDocuments
Moves content between a RichTextArea and a Document, so the light editor and the paged
one can work on the same text.
final DocumentModel model = new DocumentModel(new Document());
model.insertBlock(0, new Paragraph(model.newId('p'), RichText.of("Edit me")));
RichTextArea editor = new RichTextArea();
RichTextDocuments.show(model.getDocument(), editor);
// later, once the user has edited the text
RichTextDocuments.read(editor, new SuccessCallback<Document>() {
public void onSucess(Document d) {
model.setDocument(d);
}
});
Content goes through HTML, so what HTML cannot say -- page size, tracked changes, comments
-- is not carried. Embedded components are: the editor shows each through the image source
EmbeddedComponents registers, and reading back restores its type, size and state.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentA document made from HTML a rich text editor gave back.static voidread(RichTextArea editor, SuccessCallback<Document> callback) Reads a rich text editor's content as a document.static DocumentreadMarkdown(String markdown) Reads Markdown.static DocumentReads RTF from a string, as a clipboard gives it.static voidshow(Document d, RichTextArea editor) Shows a document in a rich text editor.static StringThe HTML a rich text editor is given for a document.static StringWrites Markdown.static StringWrites RTF.
-
Method Details
-
show
Shows a document in a rich text editor.
Parameters
-
d: the document -
editor: the editor
-
-
toHtml
-
fromHtml
-
readMarkdown
Reads Markdown. Unlike
Document.read, this reaches no other format's code, so an application that only exchanges Markdown with a rich text editor carries no DOCX, ODT or PDF support.Parameters
markdown: the source
Returns
the document
Throws
IOException: when the source nests too deeply for the thread's stack
- Throws:
IOException
-
writeMarkdown
-
readRtf
Reads RTF from a string, as a clipboard gives it. Characters above U+00FF, which RTF spells with escapes, are kept: each becomes the backslash-u control word that says it.
Parameters
rtf: the source
Returns
the document
Throws
IOException: when the source is not RTF or nests too deeply for the thread's stack
- Throws:
IOException
-
writeRtf
-
read
Reads a rich text editor's content as a document. The editor answers asynchronously.
Parameters
-
editor: the editor -
callback: given the document
-
-