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

  • This topic has 7 replies, 5 voices, and was last updated 8 years ago by Anonymous.
Viewing 6 reply threads
  • Author
    Posts
    • #79661

      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?

    • #79662

      Here’s what my Find/Change looks like: https://imgur.com/5e5LUqL

    • #79676
      Peter Kahrel
      Participant

      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

    • #79677
      Peter Kahrel
      Participant

      (Without [code] and [/code], naturally. Forgot the correct format for those.)

      • #83532
        Anonymous
        Inactive

        that awesome |

    • #83533
      David Blatner
      Keymaster
    • #83536
      Peter Kahrel
      Participant

      Well, actually, no need to play with the document’s Typeographic quotes setting. (Grep) Find ", replace with ~".

    • #83551
      Anonymous
      Inactive

      yes yes !

Viewing 6 reply threads
  • You must be logged in to reply to this topic.
>