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.
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.
Unfortunately, I have no idea how to script this challenging task.
Many thanks in advance
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(
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
Copy link to clipboard
Copied
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