简体   繁体   中英

JavaFx: how to make HTMLEditor not to create emtire HTML document?

When javafx create object of HTMLEditor it has the empty html document with the following html:

<html dir="ltr"><head></head><body contenteditable="true"></body></html>

However, I don't need entire html document. I want to work only with some node in html editor, for example with div . I tried to do

htmlEditor.setHtmlText(null) or htmlEditor.setHtmlText("")

but it is ignored. When I did

htmlEditor.setHtmlText("<div></div>")

I got:

<html dir="ltr"><head></head><body contenteditable="true"><div></div></body></html>

So, how to do it?

HtmlEditor always trying to have valid html structure, that is why it adds tags.

You need DOM manipulation library, for example jdom . Or manage DOM transition before sending to render, when applying string to editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM