2 Replies Latest reply on Jan 28, 2015 12:18 AM by Stamm

    How to tag elements with two tags?

    Stamm Level 1

      With the following function I can tag xml elements with bold and italic tags. The problem is, I also need "<b><i>" for example. Now my question is, how is this possible?

       

      function tagStyles(myXmlElement) {

          app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

          app.findChangeTextOptions.caseSensitive = false;

          app.findChangeTextOptions.includeFootnotes = app.findChangeGrepOptions.includeFootnotes = false;

          app.findChangeTextOptions.includeHiddenLayers = false;

          app.findChangeTextOptions.includeLockedLayersForFind = false;

          app.findChangeTextOptions.includeLockedStoriesForFind = false;

          app.findChangeTextOptions.includeMasterPages = false;

          app.findChangeTextOptions.wholeWord = false;

          objectToTag = myXmlElement;

          // italic conversion

          // need to be developed for other styles

          // pay attention to nested xml tags problems

          app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

          app.findGrepPreferences.findWhat = ".+";

          app.findGrepPreferences.fontStyle = "Italic";

          var myFindTexts = myXmlElement.findGrep();

          if (myFindTexts.length > 0) {

              for (var j = 0; j < myFindTexts.length; j++) {

                  var myText = myFindTexts[j];

                  var myStartIndex = myText.characters[0].index;

                  var myEndIndex = myText.characters[-1].index;

                  objectToTag = objectToTag.xmlElements.add({markupTag:"i", xmlContent:myText});

                  myShift+=2;

              }

          }

          // bold conversion

          // need to be developed for other styles

          // pay attention to nested xml tags problems

          app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

          app.findGrepPreferences.findWhat = ".+";

          app.findGrepPreferences.fontStyle = "Bold";

          var myFindTexts = myXmlElement.findGrep();

          if (myFindTexts.length > 0) {

              for (var j = 0; j < myFindTexts.length; j++) {

                  var myText = myFindTexts[j];

                  var myStartIndex = myText.characters[0].index;

                  var myEndIndex = myText.characters[-1].index;

                  objectToTag = objectToTag.xmlElements.add({markupTag:"b", xmlContent:myText});

              }

          }

          // bold italic conversion

          // need to be developed for other styles

          // pay attention to nested xml tags problems

          app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

          app.findGrepPreferences.findWhat = ".+";

          app.findGrepPreferences.fontStyle = "Bold Italic";

          var myFindTexts = myXmlElement.findGrep();

          if (myFindTexts.length > 0) {

              for (var j = 0; j < myFindTexts.length; j++) {

                  var myText = myFindTexts[j];

                  var myStartIndex = myText.characters[0].index;

                  var myEndIndex = myText.characters[-1].index;

                  objectToTag = objectToTag.xmlElements.add({markupTag:"b", xmlContent:myText});

              }

              objectToTag = myXmlElement;

              for (var j = 0; j < myFindTexts.length; j++) {

                  var myText = myFindTexts[j];

                  var myStartIndex = myText.characters[0].index;

                  var myEndIndex = myText.characters[-1].index;

                  objectToTag = objectToTag.xmlElements.add({markupTag:"i", xmlContent:myText});

              }

          }

      }

       

      When there is an element with the style "Bold Italic" it looks like this: "My element with <b></b><i>bold and italic</i> text". It should although look like this: "My element with <b><i>bold and italic</i></b> text".

       

      Does someone have a thought on this?

       

      Thanks in advance!