Page 1 of 1

Remove specified tags

Posted: Thu Jan 05, 2023 11:24 am
by shilpa
Hi Team,
I have below requirement please help me on this.
Say in web author i have selected below element.
<paratext>apple<bold>some<ital>some</ital></bold>ball</paratext>
<paratext>some text</paratex>
<paratext>some text<bold>some text</bold>some</paratext>


and when i put cursor in different location, from selected element paratext should get remove and below fragment should get insert.
apple<bold>some<ital>some<ital></bold>ball some text some text<bold>some text</bold>some

Thanks & Regards
Shilpa.P

Re: Remove specified tags

Posted: Thu Jan 05, 2023 5:19 pm
by mihaela
Hi,

The API that you can use to modify the document is ro.sync.ecss.extensions.api.AuthorDocumentController.

For your use case, you can use methods from AuthorDocumentController to:
- find all the nodes inside the selection: getNodesToSelect(int, int)
- create document fragments (from paratext nodes content for example, to be later inserted in the document): createDocumentFragment(int, int)
- delete nodes: deleteNode(AuthorNode)
- insert fragments: insertFragment(int, AuthorDocumentFragment)

These are just some examples of the methods that you can use. Please check the AuthorDocumentController documentation for more details.

Best Regards,
Mihaela

Re: Remove specified tags

Posted: Fri Jan 06, 2023 1:15 pm
by shilpa
Hi Miheala,

After adding getNodesToSelect(int, int) in my code i am getting only one node(paratext)
Actually i should get 3 nodes(paratext,bold,ital)

<paratext>apple<bold>some<ital>some</ital></bold>ball</paratext>


Please let me know what is the behavior of getNodesToSelect(int, int)?

Thanks & Regards
Shilpa.P

Re: Remove specified tags

Posted: Mon Jan 09, 2023 2:43 pm
by mihaela
Hello,

The Author nodes model is similar with the DOM model. The result of the getNodesToSelect(int, int) method is a list of first-level nodes that are included between start and end offsets.

So, regarding your sample, the method will return the parent paratext node. To find the other nodes (bold and ital) you will have to get its child nodes. The API that you can use to find the content nodes of a node is: ro.sync.ecss.extensions.api.node.AuthorParentNode.getContentNodes() (note that you must check if the node is an AuthorParentNode first).

Best Regards,
Mihaela