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
Tagged: character styles, script
- This topic has 5 replies, 2 voices, and was last updated 8 years, 4 months ago by Amit Schandillia.
-
AuthorPosts
-
-
November 23, 2015 at 4:22 am #79567Amit SchandilliaMember
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.
-
November 23, 2015 at 7:30 am #79570David BlatnerKeymaster
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>
-
November 23, 2015 at 10:37 am #79587Amit SchandilliaMember
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?
-
-
November 23, 2015 at 10:36 am #79586Amit SchandilliaMember
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?
-
November 23, 2015 at 11:04 am #79588David BlatnerKeymaster
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.
-
November 23, 2015 at 6:14 pm #79599Amit SchandilliaMember
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. :)
-
-
AuthorPosts
- You must be logged in to reply to this topic.