[JS] (CS2) How do you insert pseudo tags around italic text

I need to find all the italic text strings wherever they occur (tables, headers, footers etc) in an InDesign CS2 document and insert a pseudo-xml tag before and after each string (something like
before and <\I> after.)
I'm positive this must be possible but my limited experience has failed me so far.
Can anyone point me in the right direction please.
TIA
Doug Neale

With many thanks to the experts, I managed to sort out the table slant problem. For the benefit of all our many readers, here is the complete solution tested with a multi page document hosting all sorts of text and tables. It's quite long because I believe in plenty of comments.
// make sure we have at least one document open
if (app.documents.length == 0) {
// warn operator and exit immediately
alert("There are no open documents.");
exit();
// OK if we get here, we have an open doc
myDoc = app.activeDocument;
// set up start and end tags
startTag = "#.";// should really be "
endTag = "#:";// should really be "<\i>"
slantTagCount = 0;// initialise our two counters
italicTagCount = 0;
// If we are going to search/change something, we use preferences
// So, the first thing we have to do is clear them out;
// they're application level properties; see pages 567 and 568:
app.findPreferences = null;
app.changePreferences = null;
// use the search() method to search entire document for italic fonts
myFinds = myDoc.search('', false, false, undefined, {fontStyle : 'Italic'});
if (myFinds.length != 0) {
// myFinds will consist of an array of references into the text of the doc
// each reference pointing to a run offset
// run the loop backwards so that if we make any changes to the text runs
// it won't affect the array of references.
// now add the italic tags
for (var j = myFinds.length-1;j>=0;j--){
// at each italic text run we want to insert
// a pseudo xml tag at beginning and end
// Adding the tags is this simple (end tag first):
myFinds[j].insertionPoints.item(-1).contents = endTag;
myFinds[j].insertionPoints.item(0).contents = startTag;
italicTagCount++;
// as the italic effect can also be achieved by applying a slant to each character
// we need to check the whole document again, but this time we do it story by story
// Finding slanted text--when text.skew is not zero, text has been slanted.
// Unfortunately, what you want to look for is cases where this value is NOT zero,
// and even InDesign's grep search can't find that (it can apply NOT to character classes,
// but not to formatting attributes)--or, at least, I can't figure out how to do it.
// So you have to "roll your own." Something like this:
myStories = myDoc.stories;
for (var jj = myStories.length-1; jj >= 0; jj--) {
// loop through all the stories in the document
myStory = myStories[jj];
//Given a story "myStory"...
for(var myCounter = myStory.textStyleRanges.length -1; myCounter >= 0; myCounter --){
if(myStory.textStyleRanges.item(myCounter).skew != 0){
//Found some slanted text.
myStory.textStyleRanges.item(myCounter).insertionPoints.item(-1).contents = endTag;
myStory.textStyleRanges.item(myCounter).insertionPoints.item(0).contents = startTag;
slantTagCount++;
// the above procedure does all the italic content in tables as well as ordinary text boxes
// but only does skewed (slanted) text in ordinary text boxes.
// We need to tackle skewed text in tables separately.
for (var i = myStories.length - 1; i >= 0; i--) {
// go through every story
for (var j = myStories[i].tables.length - 1;j >= 0; j--) {
// go through every table in this story
for (var k = myStories[i].tables[j].columns.length - 1; k >= 0; k--) {
// go through every column in this table
for (var m = myStories[i].tables[j].rows.length - 1; m >= 0; m--) {
// go through every row in this column to look at each cell
myCell = myStories[i].tables[j].columns[k].cells[m];
// introduce another variable to make next bit more readable
myCellStyle = myCell.textStyleRanges;
if (myCellStyle.length !=0) {
// go through all the text ranges in this cell
for (var myCounter = myCellStyle.length - 1; myCounter >= 0; myCounter --) {
// check each range item for skew
if (myCellStyle.item(myCounter).skew != 0) {
// found some slanted text so tag it
myCellStyle.item(myCounter).insertionPoints.item(-1).contents = endTag;
myCellStyle.item(myCounter).insertionPoints.item(0).contents = startTag;
slantTagCount++;
// tell operator what we did, note that document appearance not updated until
// alert has been acknowledged by operator.
alert ("Italic Tag Count = "+italicTagCount+"\nSlant Tag Count = "+slantTagCount);
Regards,
Doug Neale

Similar Messages

  • How do you insert an electronically signed report as an appendix into a main report which will be signed electronically at a later date?

    How do you insert an electronically signed report as an appendix into a main report which will be signed electronically at a later date?

    You can add it as a file attachment. Exactly how you do this depends on the version of Acrobat you're using, but if you open the Attachments panel, you should see where you can add a file.

  • How do you insert live web pages in keynote?

    How do you insert live web pages in keynote?

    Insert a 2D Pie chart on the slide (Insert > Chart > 2D Pie), then place a circle from Shapes overlaid in the centre:

  • How can you insert "Page Break" in a pdf file so you will specify the pages

    How can you insert "Page Break" in a pdf file so you will specify the pages

    How / from what was the PDF originally created?  It would be easiest to insert page breaks into the original document, then recreate the PDF.

  • How do you insert a photo in mail

    how do you insert (as opposed to "attach") a photo or an image into an email?
    thanks

    The only way possible to send a non-text file by e-mail is as an attachment. Different e-mail programs will handle JPEG attachments differently. Some will show the attachment within the message and some will not.

  • How do you insert special characters with imovie 08?

    How do you insert special characters into a project
    with imovie 08?

    Don't think that would work. Since my "system date" is already set at 2007. I have 2 imports, one has the year as 2048, and the other at 2016!! I don't know where they are getting these dates from, but they are not the system date.
    Were the files imported directly from a camcorder or from files already on your hard drive? In the first case the year may have been taken from the time "stamp" recorded when the footage was shot (which may or may not have been correctly set by the user). On the other hand, files imported from the hard drive seem to be keyed to the date the imported file is written to the "Events" folder which, of course, reflects the current system time/date setting. That's why I said you had to then import (re-import) the files from a hard drive source -- i.e., to ensure the DTG would be re-written.

  • How do you delete a tag you no longer use in photoshop elements 12

    I have a few tags I no longer use. How do you delete a tag in Photoshop Elements 12

    Welcome to the forum.
    As Trevor points out, you need the Photoshop Elements Forum. I will Move your post to that very helpful and active forum. Your link, and any e-mail subscriptions will follow.
    Good luck,
    Hunt
    [Moved to Photoshop Elements Forum]

  • How do you insert a picture into another picture?

    How do you insert a picture into another picture.  For example, one person is missing from family photo & I'd like to insert that person's face.

    By using an external editor:
    In order of price here are some suggestions:
    Seashore (free)
    The Gimp (free)
    Graphic Coverter ($45 approx)
    Acorn ($50 approx)
    Pixelmator ($50 approx)
    Photoshop Elements ($75 approx)
    There are many, many other options. Search on MacUpdate. You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.

  • How can you start the tag config editor from a vi or when labview starts?

    how can you start the tag config editor from a vi or when labview starts?

    Hi,
    There is a VI called "dsc_TagEditorLauncher.vi" under "C:\Program Files\National Instruments\LabVIEW 7.1\project\lvdsc" folder that can be used to launch the TCE programmatically. I hope this helps.
    Best Regards,
    Remzi A.
    Applications Engineering
    National Instruments

  • How do you add meta tags to your website in Iweb

    I have always created websites in frontpage where you can add meta tags to help search engines find the website.   How do you add meta tags to the Iweb website I have created?

    Welcome to the Support Communities. Let me… Well, see for yourself by clicking HERE. You can also search for "meta tag" HERE.

  • How do you remove face tagging icon from images.  I cannot get them off some images.

    How do you remove face tagging icon from images.  I cannot get them off!  This is for adobe photoshop elements 6.   Thanks

    The links below have instructions for deleting photos.
    iOS and iPod: Syncing photos using iTunes
    http://support.apple.com/kb/HT4236
    iPad Tip: How to Delete Photos from Your iPad in the Photos App
    http://ipadacademy.com/2011/08/ipad-tip-how-to-delete-photos-from-your-ipad-in-t he-photos-app
    Another Way to Quickly Delete Photos from Your iPad (Mac Only)
    http://ipadacademy.com/2011/09/another-way-to-quickly-delete-photos-from-your-ip ad-mac-only
    How to Delete Photos from iPad
    http://www.wondershare.com/apple-idevice/how-to-delete-photos-from-ipad.html
    How to: Batch Delete Photos on the iPad
    http://www.lifeisaprayer.com/blog/2010/how-batch-delete-photos-ipad
    (With iOS 5.1, use 2 fingers)
    How to Delete Photos from iCloud’s Photo Stream
    http://www.cultofmac.com/124235/how-to-delete-photos-from-iclouds-photo-stream/
     Cheers, Tom

  • How do you insert page numbers into a pdf that combines multiple documents?

    I need to combine a number of documents into one PDF that then has correct pagination for the whole new document. How do you insert page numbers when combining into one PDF?

    Hi,
    You can go to Tool panel. Go to Pages. Click on Header& Footer -->  Add & Footer from the Add Header and Footer
    Regards,
    Ajlan Huda.

  • How do you use image tags

    How do you use Image tags. Thank you

    Hi John,
    Have you seen this video? It describes how to apply default image tags to your pictures, and then describes how to create new, custom tags. Is there something more specific that you're wondering about? I'd love to help!
    Cheers,
    Michael

  • How do you insert a submit button into your form?

    How do you insert a submit button into a form?

    Hi,
    The submit button is included automatically. If you are distributing your form as HTML you can use the Test tab to preview your form. If you are distributing your form as PDF, you would need to generate the PDF to see the submit button.
    Regards,
    Brian

  • In captivate 8, how do you insert a company logo so that it appears on every slide?

    in captivate 8, how do you insert a company logo so that it appears on every slide?

    Put it on the main master slide and check the daughter master slides. Which theme do you use? Not all daughter master slides have automatically the main master objects, that is why I'm asking about the theme.

Maybe you are looking for

  • Naming Multiple Desktops

    Can desktops be named within OSX 10.8.2?  I keep multiple desktops open for different subjects/activities and would like to title them instead of them being simply "Desktop #1", "Desktop #2" &c.  Can this be done?

  • Mac Pro refuses to sleep on it's own.

    My Mac Pro used to be able to go to sleep by setting the Energy Saver settings to automatically sleep after so many minutes. It no longer sleeps at all on it's own. Lemme explain. If I put my computer to sleep with the Apple Menu, or Power Button or

  • Messages Out of Order

    Hi there!  Hoping someone can help with this problem: all of my new emails, texts and bbm's instead of depositing on the top of my folder (newest first) are all being received throughout my inbox on different dates, rather than on today's date. Does

  • How settle to Capital work in process

    hi sap kings......... what are the steps require to setlement of AUC. explain to me detailed prcess.

  • Bi Connector Variable

    Hello, i have NW04 and i am trying to use the bi connector. i sucessfullt instaled and was able to view a bex query. now i am trying to use variables for this bex query. i can find the variable in the query throught the SAPVariable finder. but after