How to get marker content

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

How to get marker content

Post by manojdcoder » Tue Jan 12, 2021 12:13 pm

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());

cristi_talau
Posts: 341
Joined: Thu Sep 04, 2014 4:22 pm

Re: How to get marker content

Post by cristi_talau » Tue Jan 12, 2021 2:36 pm

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

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

Re: How to get marker content

Post by manojdcoder » Tue Jan 12, 2021 8:58 pm

From the fragment, we get access to all first level AuthorNode(s), not sure how to traverse through child nodes from there. Any pointers?

cristi_talau
Posts: 341
Joined: Thu Sep 04, 2014 4:22 pm

Re: How to get marker content

Post by cristi_talau » Tue Jan 12, 2021 9:26 pm

Depending on the node's getType() result, you can cast it to AuthorParentNode and use getContentNodes() to access children.

Post Reply