Skip navigation
Currently Being Moderated

Tagging for Character Style

Apr 17, 2012 5:34 AM

Hi All,

 

Need to insert tagging (character style name) surrounding the text which has character styles applied in InDesign document.

 

Example: This is <italic>an</italic> example of <bold>character style</bold> tagging text.

 

Please provide JS code for this.

 

Thanks in advance,

Mon

 
Replies
  • Currently Being Moderated
    Apr 23, 2012 5:15 AM   in reply to designmon79

    I think a simple grep find/change will work, look at the image below.

    The .+ finds any character, one or more times,

    In the Change To field type the code you want to use eg <bold>$0</bold>, the $0 puts back what is found.

    Finally, in the Find Format area, select the formating that you are looking for.

     

    findChange.jpg

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 23, 2012 6:57 AM   in reply to designmon79

    > But I need Javascript code for this

     

    Virtually demanding a script rarely helps. Maybe you should ask someone if they were willing to write the code for you. And if you offer to pay something for it I'm sure someone will sort you out.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 9:10 AM   in reply to designmon79
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 10:52 PM   in reply to designmon79

    Hi,

        Try this. I'm also fresher...

    First u have to create tags manually with names b, bi,i, sc (bold,bolditalic,italic, small caps)...

    then execute this js...

     

    docObj=app.activeDocument;

    xmlObj = docObj.xmlTags;

    pageObj=docObj.pages.item(0);

    myTextFrame=pageObj.textFrames.item(0);

    myText=myTextFrame.parentStory.paragraphs.item(0);

     

     

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

    app.findTextPreferences.fontStyle = "Bold";

    app.changeTextPreferences.markupTag=xmlObj[0].name;

    alert(app.changeTextPreferences.markupTag);

    app.activeDocument.changeText();

     

     

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

    app.findTextPreferences.fontStyle = "Bold Italic";

    app.changeTextPreferences.markupTag=xmlObj[1].name;

    alert(app.changeTextPreferences.markupTag);

    app.activeDocument.changeText();

     

     

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

    app.findTextPreferences.fontStyle = "Italic";

    app.changeTextPreferences.markupTag=xmlObj[2].name;

    alert(app.changeTextPreferences.markupTag);

    app.activeDocument.changeText();

     

     

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

    app.findGrepPreferences.capitalization = Capitalization.SMALL_CAPS;

    app.changeGrepPreferences.markupTag=xmlObj[4].name;

    alert(app.changeGrepPreferences.markupTag);

    app.activeDocument.changeGrep();

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2012 12:00 AM   in reply to designmon79

    Hi mon,

    I can't get ur question clearly. Please tell me with an simple example.

     

    Thanks & Regards,

    Vel.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2012 1:29 AM   in reply to designmon79

    < and > appear because you put them there. Instead of

     

    app.changeGrepPreferences.changeTo = "<$0>"

     

    use

     

    app.changeGrepPreferences.changeTo = "$0"

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2012 1:40 AM   in reply to Peter Kahrel

    I also think to say the same thing as said by peter. But u expecting the same thing mon?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2012 3:35 AM   in reply to designmon79

    Try this:

     

    styleCodes = ['Bold', 'Italic', 'Bold Italic'];
    styleTags = ['bold', 'italic', 'boldItalic'];
     
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = '.+';
    for (i = 0; i < styleCodes.length; i++)
        {
        app.findGrepPreferences.fontStyle = styleCodes[i];
        app.changeGrepPreferences.changeTo = '<'+styleTags[i]+'>$0<' + '/' + styleTags[i] + '>';
        app.activeDocument.changeGrep();
        }
    

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2012 4:57 AM   in reply to designmon79

    True, that's what you wanted:

     

     

    charStyles = app.activeDocument.allCharacterStyles;
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = '.+';
    // Start at 1 to skip charstyle [None]
    for (i = 1; i < charStyles.length; i++)
        {
        app.findGrepPreferences.appliedCharacterStyle = charStyles[i];
        app.changeGrepPreferences.changeTo = '<'+charStyles[i].name+'>$0<' + '/' + charStyles[i].name + '>';
        app.activeDocument.changeGrep();
        }
    

     

    Peter

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points