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

Converting Nested Styles into Local Character Styles

Participant ,
Feb 25, 2024 Feb 25, 2024

Copy link to clipboard

Copied

Hello, I am having some problems with paragraph styles (when I export to html or epub) where I use grep style.
To convert grep styles to local character styles

http://in-tools.com/products/scripts/

I use (Apply Nested Style). But here, my extra underlined words on the paragraph are not visible.
Does anyone know another solution? Thanks in advance for your help.

 

TOPICS
Scripting

Views

223

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

Community Expert , Mar 01, 2024 Mar 01, 2024

In that case you use this one:

 

(function () {
  
  var indd = app.documents.item(0);

  function applyAsLiteral (gstyle) {
    app.findGrepPreferences.findWhat = gstyle.grepExpression;
    app.changeGrepPreferences.appliedCharacterStyle = gstyle.appliedCharacterStyle;
    indd.changeGrep();
  }

  function grepStyleToNormal (ps) {
    var gstyles = ps.nestedGrepStyles.everyItem().getElements();
    for (var i = 0; i < gstyles.length; i++) {
      if (gstyles[i].name !== 'myChar') {
        app
...

Votes

Translate

Translate
Participant ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

I'm not sure I understand your question. Can you provide some more detail about what your desired vs. actual outcome is, and a screenshot?

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
Participant ,
Feb 29, 2024 Feb 29, 2024

Copy link to clipboard

Copied

Thank you for your interest. I guess I didn't explain it clearly. But @Peter Kahrel saw the problem and helped me find the right answer. Thanks a lot.

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
Community Expert ,
Feb 29, 2024 Feb 29, 2024

Copy link to clipboard

Copied

The In-Tools script doesn't deal with GREP styles, that's why it doesn't work for you.

 

Here's a script that converts GREP styles to character styles applied in the document. Be aware though that any character style applied directly will be overridden, and also that GREP styles are additive, i.e. they don't cancel each other out, whereas directly applied character style do cancel each other out: the last character style applied wins.

 

 

(function () {
  
  var indd = app.documents.item(0);

  function applyAsLiteral (gstyle) {
    app.findGrepPreferences.findWhat = gstyle.grepExpression;
    app.changeGrepPreferences.appliedCharacterStyle = gstyle.appliedCharacterStyle;
    indd.changeGrep();
  }

  function grepStyleToNormal (ps) {
    var gstyles = ps.nestedGrepStyles.everyItem().getElements();
    for (var i = 0; i < gstyles.length; i++) {
      applyAsLiteral (gstyles[i]);
    }
    ps.nestedGrepStyles.everyItem().remove();
  }

  app.findGrepPreferences = app.changeGrepPreferences = null;
  var pstyles = indd.allParagraphStyles;
  for (var i = pstyles.length-1; i >= 1; i--) {
    grepStyleToNormal (pstyles[i]);
  }

}());

 

 

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
Participant ,
Feb 29, 2024 Feb 29, 2024

Copy link to clipboard

Copied

Worked great Peter, thank you very much.

Except for one problem you mentioned. Subsequently applied character styles.
There is a character style called “myChar” which I then applied. How can I proceed if I don’t want this to change? Thank again...

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
Community Expert ,
Mar 01, 2024 Mar 01, 2024

Copy link to clipboard

Copied

In that case you use this one:

 

(function () {
  
  var indd = app.documents.item(0);

  function applyAsLiteral (gstyle) {
    app.findGrepPreferences.findWhat = gstyle.grepExpression;
    app.changeGrepPreferences.appliedCharacterStyle = gstyle.appliedCharacterStyle;
    indd.changeGrep();
  }

  function grepStyleToNormal (ps) {
    var gstyles = ps.nestedGrepStyles.everyItem().getElements();
    for (var i = 0; i < gstyles.length; i++) {
      if (gstyles[i].name !== 'myChar') {
        applyAsLiteral (gstyles[i]);
      }
    }
    ps.nestedGrepStyles.everyItem().remove();
  }

  app.findGrepPreferences = app.changeGrepPreferences = null;
  var pstyles = indd.allParagraphStyles;
  for (var i = pstyles.length-1; i >= 1; i--) {
    grepStyleToNormal (pstyles[i]);
  }

}());

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
Participant ,
Mar 01, 2024 Mar 01, 2024

Copy link to clipboard

Copied

LATEST

Hi @Peter Kahrel;

It works perfectly, thank you very much, I can do more specific work on this script. 

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