Indesign script to add HTML tags based on character styles

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Indesign script to add HTML tags based on character styles

Viewing 4 reply threads
  • Author
    Posts
    • #79567

      I have an InDesign document with text styled as one of the following custom character styles throughout the document:

      – character-bold
      – character-italic
      – character-bolditalic
      – [none]

      I am trying to write a script to scan the entire document and wrap each text of a particular character style with the appropriate HTML tag, except of course the text without any assigned character style. Thus, the following text:

      The quick **brown** fox **jumps ri**ght *ov*er ***the*** lazy dog. (where, ** represents bold, * represents italics, and *** represents bold-italic character styles)

      …should look like:

      The quick <b>brown</b> fox <b>jumps ri</b>ght <i>ov</i>er <b><i>the</i></b> lazy dog.

      Is this doable? I am sure it is. I don’t mind using some kind of GREP/Find-Change method if possible. I don’t want to use “Export to HTML” because there are some custom tags that won’t show that way.

    • #79570
      David Blatner
      Keymaster

      Sure, you should be able to use the GREP tab of the find/change dialog box to find .+ (and set it to the character formatting you want, in the Find Format section at the bottom of the dialog box. Then, in the Change To field, type <i>$1<\i>

      • #79587

        Thank you for the quick response, David. Just tried doing as you suggested but I must be doing something stupid because the “$1” bit is replacing the text that needs to be within the tags. For instance:
        This is a nice book. (where nice is in bold)
        …turns into:
        This is a <i>$1</i> book.
        How can I make Indesign see $1 as a wildcard variable for the text being tagged?

    • #79586

      Thank you for the quick response, David. Just tried doing as you suggested but I must be doing something stupid because the “$1” bit is replacing the text that needs to be within the tags. For instance:

      This is a nice book. (where nice is in bold)

      …turns into:

      This is a <i>$1</i> book.

      How can I make Indesign see $1 as a wildcard variable for the text being tagged?

    • #79588
      David Blatner
      Keymaster

      Perhaps you’re not in the GREP tab of the Find/Change dialog box? Or you put a backslash before the $ character? Not sure what else would do that.

    • #79599

      Worked like a charm…I just changed $1 to $0 and that did the trick. No idea how it worked but it did! I will now study more about these wildcard numbers and what they mean…seems like a mighty handy tool to me. Thanks a ton. :)

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