• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to let chars with different character formats correspond with each other

New Here ,
Jul 21, 2019 Jul 21, 2019

Copy link to clipboard

Copied

Is there a way to let pairs of different character formats that encloses any text between correspond with each other?

The following initial situation: My basic text contains hundreds of strings starting with a superscript lowercase letter (character format "SUB" , blue coloured). Then there is arbitrarily formatted text, then at the end of a word (rarely in the word) there is another lowercase letter with the character format "SUB". Immediately afterwards, a superscript lowercase letter with the character format "Source", red coloured, appears.

initial_situation.jpg

The probably very different task is to

-- delete the second lowercase letter (blue coloured) that is equal to the first lowercase letter (blue coloured) and

-- to assign the content of the last lowercase letter with the character format "Source" (red coloured) to the first lowercase letter.

result.jpg

Unfortunately, I have no idea how to script this challenging task.

Many thanks in advance

TOPICS
Scripting

Views

443

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jul 21, 2019 Jul 21, 2019

Hi Jürgenl,

A quick sketch to get started:

// YOUR SETTINGS

// ---

const EMBED_STYLE = "SUB";

const INFO_STYLE  = "Source";

(function(/*Document*/doc,  r,a,s,w,t,q,cc,x)

{

    if( !doc ) return;

    app.findGrepPreferences = null;

    app.findGrepPreferences.properties =

    {

        findWhat: "\\l{1,2}",

        position: +Position.SUPERSCRIPT,  // or +Position.OT_SUPERSCRIPT (?)

    };

   

    for( r=0, a=doc.stories.everyItem().findGrep() ; s=a.pop() ; )

    for( q=cc='', w=2 ; t=s.pop() ; )

    {

        if(

...

Votes

Translate

Translate
Guide ,
Jul 21, 2019 Jul 21, 2019

Copy link to clipboard

Copied

Hi Jürgenl,

A quick sketch to get started:

// YOUR SETTINGS

// ---

const EMBED_STYLE = "SUB";

const INFO_STYLE  = "Source";

(function(/*Document*/doc,  r,a,s,w,t,q,cc,x)

{

    if( !doc ) return;

    app.findGrepPreferences = null;

    app.findGrepPreferences.properties =

    {

        findWhat: "\\l{1,2}",

        position: +Position.SUPERSCRIPT,  // or +Position.OT_SUPERSCRIPT (?)

    };

   

    for( r=0, a=doc.stories.everyItem().findGrep() ; s=a.pop() ; )

    for( q=cc='', w=2 ; t=s.pop() ; )

    {

        if( w != t.length ){ w=2; continue; }

        x = t.characters[0].appliedCharacterStyle.name;

        if( EMBED_STYLE != x ){ INFO_STYLE==x && (w=2); continue; }

        if( 2==w )

        {

            INFO_STYLE == t.characters[1].appliedCharacterStyle.name

            && ( cc=(q=t).contents, w=1 );

        }

        else

        {

            t.contents == cc.charAt(0)

            && ( ++r, q.characters[0].remove(), t.contents=cc.charAt(1) );

            w = 2;

        }

    }

   

    alert( "Edited tags: " + r );

})( app.properties.activeDocument );

@+

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

LATEST

Hello Marc, thank you very much for your effort and this ingenious script. It saved me hours i don't have. Since i don't know if the editor has marked everything correctly (subsript small letters in blue) I added two lines for my visual control:

var newCharStyle = app.activeDocument.characterStyles.item("Source0"); 

t.applyCharacterStyle(newCharStyle);

I don't understand your script completely yet, but in the moment i can't steel the time to understand it better. But i will do that as soon as possible. Can i ask you a few more questions a few days later?

many thanks again

greetings jürgen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines