Jump to content

DW Batch S&R


vchris

Recommended Posts

I work a lot with Dreamweaver. I usually have to do many search and replace and they're pretty much always the same (change <b> for <strong>, <i> for <em>, <p align="center"> for <p class="alignCenter"> and so on...). I know that in DW I can save a S&R query. I've tested a bit and it seems like I can only save one query at once. So <b> - <strong> is 1 query (file) and <i> - <em> is another query. It doesn't seem like it's possible to load multiple queries at once. I've looked at the code inside a query file and it's pretty simple except when I attempt to include my 2 queries inside one file, it's works but only the last query in the file is executed.Query (b - strong):

<?xml version="1.0"?><dwquery>  <queryparams matchcase="false" ignorewhitespace="false" useregexp="false" wholeword="false" />  <find>	<qtext qname="<b>" qraw="true"></qtext>  </find>  <replace action="replaceText" param1="<strong>" param2=""/></dwquery>

I've tried adding another dwquery element but only the last dwquery element is executed. I also tried adding another queryparams, find, replace elements but still doesn't work.Anyone has any idea if it's possible? Could save me lots of time.

Link to comment
Share on other sites

I don't know how to do it in DW since I replaced it /w hand-coding in notepad++ a while back but I know you can do it with php.Just setup a php processor that loads and processes the file line by line and uses preg_replace() to change the syntax. Or I can...I whipped up this little toolie in about an hour (because I'm still a php newb). I call it the DepreGrubberJust change the $LoadFile variable to the original and change the $Output variable to name the new file that will be generated and Voila.

<?php$LoadFile = "input.html";$OutputFile = "output.html";$fhI = fopen($LoadFile, 'r') or die("Can't open file");$fhO = fopen($OutputFile, 'w') or die("Can't open file");$count = 0;while(!feof($fhI)) {  $line = fgets($fhI);		$find[0] = 		'/<html>/';	$replace[0] = 	'<TuMadre>';		$find[1] = 		'/<\x2fhtml>/';	$replace[1] = 	'</TuMadre>';		$find[2] = 		'/<body>/';	$replace[2] = 	'<Corps>';		$find[3] = 		'/<\x2fbody>/';	$replace[3] = 	'</Corps>';			$stringData = preg_replace($find, $replace, $line);	fwrite($fhO, $stringData);  }fclose($fhI);fclose($fhO);echo "Tu Madre un feo que asusta";?>

This script is awesome because you can add as many replace-strings as you want and it works really fast. The only downside is that those pesky front slashes have to be ascii encoded. For a complete ascii table go here:http://ascii-table.com/index.phpAll this needs is a little fancy front end, and a complete index of deprecated tags and their replacements and you'll never have to go back to DW for bringing code up to current standards again.Hope that helps

Link to comment
Share on other sites

The only downside is that those pesky front slashes have to be ascii encoded
What is wrong with just escaping them, e.g.
/<\/html>/

Link to comment
Share on other sites

Good point... Did I mention that I'm a newb when it comes to regular expressions. I didn't happen to see \/(escaped front-slash) under the list of escaped characters.Thanks

Link to comment
Share on other sites

Thanks but I already created myself a while ago a ColdFusion script that searches and replaces what I need. The problem with that script is it only searches one file at a time which is very slow. The thing is DW is so much more powerful not just because it can replace a <b> tag by a <strong> tag also because it can remove, set, change certain attributes in specified tags and more... It can search opened files, folder, current file, selected code that's why I want to stick with DW. I guess I could change my script to search a folder instead of file, this way it would do most of the work and it would be a lot faster than DW.

Link to comment
Share on other sites

It could be done pretty easily. All you'd have to do is pick a root dir, load the directory structure into an array queue, and rebuild it in an output root.I was thinking about extending this little snippet to load the tags from an xml file (which would also automatically exit certain strings). Making it process multiple files is also a really good idea. When you originally posted this, I thought your intention was just to update old deprecated HTML to a current DTD compliant (X)HTML. For a static purpose such as removing deprecated code, having all of the settings statically coded would be very quick and efficient, but for on the fly changes like you describe, DW is obviously more flexible.

Link to comment
Share on other sites

In Dreamwaver 8 and later (I don't know about earlier), your S&Rs can be regular expressions.I'm not sure, but I think replacements can use $N references to denote a part that was matched. There might be a way to forge a single query that will do all of the tag replacements you want.Honestly said though, I can't think of the regular expression that will do this. Just wanted to give a hint on that, so that you may think about it too.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...