Page 1 of 1

How to get marker content

Posted: Tue Jan 12, 2021 12:13 pm
by manojdcoder
When a change marker is being removed, I would like to read the content of the marker. The code below gives me the plain text between the offsets, is it possible to get the actual XML content thats being removed or added by marker Or perhaps the HTML content in editor for this marker?

Code: Select all

Segment chars = new Segment();
model.getAuthorDocumentController().getChars(highlight.getStartOffset(), (highlight.getEndOffset() - highlight.getStartOffset()) + 1, chars);
data.put(RESPONSE_ATTRIBUTE_CONTENT, chars.toString());

Re: How to get marker content

Posted: Tue Jan 12, 2021 2:36 pm
by cristi_talau
Hello,

To get an XML representation you can use the AuthorDocumentController.createDocumentFragment() API. This returns an AuthorDocumentFragment that you can traverse and generate the XML text.

To get an HTML representation, you can use the "copy-as-html" feature, but without setting the user clipboard. This requires you to us a code as below:

Code: Select all

AuthorSelectionAndCaretModel selectionModel = authorDocModel.getSelectionModel();
selectionModel.moveTo(start);
selectionModel.moveTo(end, true);
AuthorClipboardObject clipboardObject = authorDocModel.getActionsSupport().handleCopy();
clipboardObject.getHtmlContent();
Best,
Cristian

Re: How to get marker content

Posted: Tue Jan 12, 2021 8:58 pm
by manojdcoder
From the fragment, we get access to all first level AuthorNode(s), not sure how to traverse through child nodes from there. Any pointers?

Re: How to get marker content

Posted: Tue Jan 12, 2021 9:26 pm
by cristi_talau
Depending on the node's getType() result, you can cast it to AuthorParentNode and use getContentNodes() to access children.