How to add data to insert/replace fragment

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
akshatTR
Posts: 7
Joined: Mon Dec 12, 2022 11:19 pm

How to add data to insert/replace fragment

Post 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);
            }); 
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: How to add data to insert/replace fragment

Post 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
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply