Page 1 of 1

How to add data to insert/replace fragment

Posted: Wed Dec 14, 2022 3:09 am
by akshatTR
Hello, I am trying to enclose certain text in fragment inside the Web author. For example if the text I want to wrap is "truthness" it would replace the word "truthness" in a tag like this -

Code: Select all

<reference referenceGuid="someguid">truthness</reference>
I have been playing around with Insert and Replace fragment but I think it is only taking self enclosed tags

Code: Select all

<reference />
as input for fragment parameter.

Here is the code I am using that almost works except it adds data inside the tag as "reference" (<reference>reference</reference> instead of <reference>truthness</reference>)

Code: Select all

var data = '<reference />';
        editorGlobal.getActionsManager().invokeOperation(
              'ro.sync.ecss.extensions.commons.operations.InsertFragmentOperation', 
              {fragment: data}, 
              function(e) {
                console.log('Done!', e);
            }); 

Re: How to add data to insert/replace fragment

Posted: Wed Dec 14, 2022 2:35 pm
by mihaela
Hi,

The InsertFragmentOperation that you use will insert an empty reference element. The "reference" text that you see between the start and end tag of the inserted element is the placeholder that is displayed when the element is empty (it renders the name of the element by default).

Depending on what you want to achieve, there are multiple solutions.
For example, if you want to surround the selected content from the editor with a reference element, you can use the SurroundWithFragmentOperation.
If you want to surround specific content that is not selected, you can create and use a custom AuthorOperation that uses the ro.sync.ecss.extensions.api.AuthorDocumentController.surroundInFragment(String, int, int) API.

Best Regards,
Mihaela