How to prevent auto-tag-completion on "search and replace" in Dreamweaver MX 2004

Posted on 2006-04-13
Last Modified: 2010-04-25
I'm using Dreamweaver MX 2004 to update some badly-marked-up HTML documents.  My process is to use the Find/Replace feature to blow through whole directory trees of HTML and fix a few tags and issues at a time.  It works quite well.

There is a particular problem that keeps coming up.  I don't know if it's me, or if it's Dreamweaver.  It would seem that when I attempt to "surround" a particular tag sequence with another tag, I don't get my desired results.  Let me 'splain with an example:

Existing HTML looks like this:

<a name="target">Blah De Blah</a>

What I want the Replace feature to do is this:

<h2><a name="target">Blah De Blah</a></h2>

(I assumed that I would have to do that in TWO steps; using 'Add Before Start Tag', and then 'Add After End Tag' in my search/replace activity).

However, what I get when I search for '<a>' tags with a 'name' attribute of '[any_value]' and tell DW to 'Add a <h2> Before Start Tag' is this:

<h2></h2><a name="target">Blah De Blah</a>

Likewise, if I try 'Add After End Tag', I get:

<a name="target">Blah De Blah</a><h2></h2>

I've tried turning OFF the 'Auto Tag Completion' feature in Edit > Preferences > Code Hints, but that doesn't seem to have an effect on Search/Replace.

Any ideas on how I can fix this?  I can't use a different version of Dreamweaver, and I really can't use another product (corporate bureaucracy at work here).

Question by:mpp1031
    LVL 70

    Accepted Solution

    Hi mpp1031,

    Two things to try:

    1) Go to Edit | Preferences | Code Rewriting and turn off "Fix invalidly nested and unclosed tags"

    That may or may not work.  I can't fully replicate what you are seeing in DW 8.  When I tried it, DW closed the h2 tag if it was not in a paragraph tag.  In other words, if the <a> occurred within a <p>, then the <h2> did not close.  When the <a> was not in a <p>, the tag auto-closed when using F/R for specific tags.

    Now that I think about it, also check under General for "Switch to plain paragraph after heading" to see if it is enabled or not.  If enabled, try disabling.

    2) Don't use tag search to do something that is this simple.

    Just search in Source Code for <a and replace it with <h2><a


    /a> replaced with  /a></h2>

    This worked no matter where the <a> was located, unless <a and /a> appear in your content as text (not links).


    Author Comment

    I'm not at work right now, but on Monday I'll try #1.

    Problem with your #2 suggestion is that I have *other* <a> tags that *are* links (i.e. with href attributes) that I would not want to enclose in <h2></h2> tags.  I suppose I could try doing a more complex Regular Expression search, but I suck at Regexes, so that's a last resort.
    LVL 70

    Expert Comment

    by:Jason C. Levine
    Meh.  Obviously you can start the h2 by searching for <a name= but closing them would be tough.

    The better question to be asking here is if MM is going to let you put a new tag in front of or behind a tag, why the heck couldn't they have added a wrap tag option to the F/R function?

    I did a little more digging and #1 should work for you.  What appears to be happening is that by using tag F/R, DW is re-validating the code as it goes along.  So by turning off the validation it should be okay.  I'm not at my normal location this week, so I can't test it first :(

    The DW regular expressions are not like "normal" regular expressions.  They are a little simpler to define and use and MM devnet has a good tutorial:

    I can't normally write a regex to save my life, but I have been able to write them in DW with only a minimum of pain.  Bonus:  you can save the F/R definitions once you get one that works...

    Author Comment

    I think I've found a compromise *solution* (however "bootleg" it might be):

    I do my F/R, but instead of telling DW to replace with <h2>, I specify \h2\ (since backslashes aren't typically used very much in these pages, if at all... I hope), and \/h2\ for the end tag, of course.  It takes me FOUR steps instead of 1 or 2, but it does get my desired result.  I suppose I could use some other character (or cominbation of characters) instead of the backslash.

    I'll leave this open, briefly, if anyone else has any comments or a better/different solution...

    jason1178, I checked this morning when I got in, and I already had the "Fix nested tags" feature disabled, as well as ALL the code-rewriting options, and it still doesn't work as it *should*.  I even tried turning them back on in various combinations, even specifying that HTM and HTML documents never be rewritten.  DW didn't care.  It insists on throwing the whole tag combination in there, even if I only want the opening tag.  Weird.
    LVL 70

    Expert Comment

    by:Jason C. Levine
    I can confirm that it is odd.  I tested it over the weekend and played around with all the various toggles and got the same results.  Again, the only thing I can think of is that when F/R on tags, DW goes into validation mode and closes the tag no matter what you specify.

    Oh well.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Specialist

    HTML5 development skills are critical to all developers. HTML5 is the foundation to almost any development process. That's why business, design studios, development shops and other organizations need HTML5 developers. Get your foot in the door as a HTML5 specialist.

    Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
    This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now