Convert smart (curly) quotes to dumb (straight) quotes in InDesign using JS
- This topic has 7 replies, 5 voices, and was last updated 8 years ago by .
- You must be logged in to reply to this topic.
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Convert smart (curly) quotes to dumb (straight) quotes in InDesign using JS
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Convert smart (curly) quotes to dumb (straight) quotes in InDesign using JS
Tagged: find/change, script
I am trying to write a script to automatically convert all curly double quotes (“”) in a text box into straight double quotes (“). Here’s all that I’ve tried so far and none of them seem to be working:
imgtext.contents = imgtext.contents.replace(/[\u201C\u201D]/g, ‘”‘);
imgtext.contents = imgtext.contents.replace(/[\u201C\u201D]/g, “\u0022”);
imgtext.contents = imgtext.contents.replace(/[\u201C\u201D]/g, ‘\^”‘);
imgtext.contents = imgtext.contents.replace(/[\u201C\u201D]/g, ‘^\”‘);
imgtext.contents = imgtext.contents.replace(/[\u201C\u201D]/g, ‘\^\”‘);
What am I missing here?
Here’s what my Find/Change looks like: https://imgur.com/5e5LUqL
You’re replacing text content, which is dangerous because you may delete index markers, cross-references, etc. etc. And you might make a mess of formatting. It’s safer to let InDesign do the replacements rather than JavaScript. Something like this:
[code]app.documents[0].textPreferences.typographersQuotes = false;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '(["'])';
app.changeGrepPreferences.changeTo = '$1';
imgtext.changeGrep();
app.documents[0].textPreferences.typographersQuotes = true;[/code]
Peter
(Without [code] and [/code], naturally. Forgot the correct format for those.)
There may be an easier way, just using Find/Change:
https://creativepro.com/curly-typography-quotes-turn-off.php/comment-page-1#comment-1096377
Well, actually, no need to play with the document’s Typeographic quotes setting. (Grep) Find "
, replace with ~"
.
yes yes !
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies allows us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.
You have to be logged in to save.
Not a member? Join Today - it's FREE!