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.
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
...
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?
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.
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]);
}
}());
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...
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]);
}
}());
Copy link to clipboard
Copied
Hi @Peter Kahrel;
It works perfectly, thank you very much, I can do more specific work on this script.