5 Replies Latest reply on Oct 29, 2008 4:41 AM by Newsgroup_User

    Have list of site changes: Can DW CS3's Find-and-Replace be driven by a script?  Or...?

    hen3ry Level 1
      Folks:

      DW CS3 MacOS 10.4.x.11

      I am renovating a site of 100+ pages. This requires making some systematic edits, which I would like to automate as much as possible -- using the DW Find-and-Replace mechanism if possible.

      I don't think the nature of the changes is particularly relevant, but I'll share it: I need to remove hundreds of mailto's from the old code and replace them with links to a common Contact form, with the specific email address supplied as a parameter. There's a bit of re-arrangement to do. I think a true regexp expert might be able to handle the job completely using regular expressions, as DW Find-and-Replace is capable, but I'm not nearly skilled enough.

      I have a text file listing of changes I need to make, something like this:

      file1: old-html-text1 ---> new-html-text1
      file2: old-html-text2 ---> new-html-text2

      ....

      fileM: old-html-textN ---> new-html-textN

      There are 150+ of these.

      Is there a way to feed such a file to DW as a script? Obviously, I'm willing to edit the text file as needed.

      The only alternative I can figure out is to use UNIX command-line tools, but that seems a bit heavy-handed -- those tools don't know about the composition of the site and they don't know anything about HTML. DW Find-and-Replace has awareness of both -- which somehow seems to be a worthwhile advantage. I'm also exploring scripting capabilities of the programmer's editor jEdit.

      Or should I just bite the bullet, get out a bottle of pain-reliever tablets, and do the 150+ edits manually?

      Am I missing something incredibly obvious?

      TIA,

      Henry
        • 1. Re: Have list of site changes: Can DW CS3's Find-and-Replace   be   driven by a script?  Or...?
          Level 7
          hen3ry wrote:
          > Folks:
          >
          > DW CS3 MacOS 10.4.x.11
          >
          > I am renovating a site of 100+ pages. This requires making some systematic
          > edits, which I would like to automate as much as possible -- using the DW
          > Find-and-Replace mechanism if possible.
          >
          > I don't think the nature of the changes is particularly relevant, but I'll
          > share it: I need to remove hundreds of mailto's from the old code and replace
          > them with links to a common Contact form, with the specific email address
          > supplied as a parameter.

          Perhaps you could give an example:


          Change this: <a href="mailto:example@example.com">
          To this: ??

          Mick






          There's a bit of re-arrangement to do. I think a true
          > regexp expert might be able to handle the job completely using regular
          > expressions, as DW Find-and-Replace is capable, but I'm not nearly skilled
          > enough.
          >
          > I have a text file listing of changes I need to make, something like this:
          >
          > file1: old-html-text1 ---> new-html-text1
          > file2: old-html-text2 ---> new-html-text2
          >
          > ....
          >
          > fileM: old-html-textN ---> new-html-textN
          >
          > There are 150+ of these.
          >
          > Is there a way to feed such a file to DW as a script? Obviously, I'm willing
          > to edit the text file as needed.
          >
          > The only alternative I can figure out is to use UNIX command-line tools, but
          > that seems a bit heavy-handed -- those tools don't know about the composition
          > of the site and they don't know anything about HTML. DW Find-and-Replace has
          > awareness of both -- which somehow seems to be a worthwhile advantage. I'm
          > also exploring scripting capabilities of the programmer's editor jEdit.
          >
          > Or should I just bite the bullet, get out a bottle of pain-reliever tablets,
          > and do the 150+ edits manually?
          >
          > Am I missing something incredibly obvious?
          >
          > TIA,
          >
          > Henry
          >

          • 2. Re: Have list of site changes: Can DW CS3's Find-and-Replace be driven by a script?  Or...?
            hen3ry Level 1
            Michael White:

            My question is about scripting, preferably within DW, to make lots of repetitive changes, not about the specific nature of the changes. Since you ask, here's a generalized model for what I have in mind:

            <a href="mailto:example@sample.com">Homer Simpson</a>

            to something like

            <a href="mailform.php?a=example&b=sample&c=com&d=Homer&e=Simpson">Contact Homer Simpson<a>

            Henry
            • 3. Re: Have list of site changes: Can DW CS3's   Find-and-Replace be   driven by a script?  Or...?
              Level 7
              hen3ry wrote:
              > Michael White:
              >
              > My question is about scripting, preferably within DW, to make lots of
              > repetitive changes, not about the specific nature of the changes. Since you
              > ask, here's a generalized model for what I have in mind:
              >
              > <a href="mailto:example@sample.com">Homer Simpson</a>
              >
              > to something like
              >
              > <a href="mailform.php?a=example&b=sample&c=com&d=Homer&e=Simpson">Contact
              > Homer Simpson<a>
              >
              > Henry
              >
              look for: mailto:([^@]*)@([^.]*)\.([^"]*)">([^ ]*) ([^"]*)"

              Replace with: mailform.php?a=$1&b=$2&c=$3&d=H$4&e=$5">Contact $4 $5</a>


              Mick


              • 4. Re: Have list of site changes: Can DW CS3's Find-and-Replace be driven by a script?  Or...?
                hen3ry Level 1
                Mick:

                So... the answer is "No need to script, no way to script in DW, just use the right regexp magic in the DW search-and-replace."

                Right, that works! Provided someone is kind enough to provide the regexp magic -- You. Thank you very much!

                Ummm, maybe you were challenging me, because I found your search string lacked a trailing

                </a>

                at the end and your replace string included an un-needed 'H' character.

                Thanks for the ready-made solution, and the encouragement that even mere mortals like me can use regexes. I sorta, kinda understand what you did... but it would take me hours and hours to do it from scratch.

                Thanks for helping me get rid of hundreds of mailtos: my clueless predecessor left me!

                Problem solved.

                Henry
                • 5. Re: Have list of site changes: Can DW CS3's   Find-and-Replace be   driven by a script?  Or...?
                  Level 7
                  hen3ry wrote:
                  > Mick:
                  >
                  > So... the answer is "No need to script, no way to script in DW, just use the
                  > right regexp magic in the DW search-and-replace."
                  >
                  > Right, that works! Provided someone is kind enough to provide the regexp
                  > magic -- You. Thank you very much!
                  >
                  > Ummm, maybe you were challenging me, because I found your search string
                  > lacked a trailing
                  >
                  > </a>
                  >
                  > at the end and your replace string included an un-needed 'H' character.

                  oops

                  look for: mailto:([^@]*)@([^.]*)\.([^"]*)">([^ ]*) ([^"]*)"



                  The 5 parenthesised expressions are simple enough:
                  $1. Anything but an "@", followed by an "@".
                  $2. Similarly, a full stop. (Note the escape: "\." )
                  $3 "
                  $4. [space]
                  $5."

                  Bada Bing.
                  Mick





                  >
                  > Thanks for the ready-made solution, and the encouragement that even mere
                  > mortals like me can use regexes. I sorta, kinda understand what you did... but
                  > it would take me hours and hours to do it from scratch.
                  >
                  > Thanks for helping me get rid of hundreds of mailtos: my clueless predecessor
                  > left me!
                  >
                  > Problem solved.
                  >
                  > Henry
                  >
                  >