Ask a Question related to Macromedia Exchange Dreamweaver Extensions, Design and Development.
-
David Stiller #1
regex replace string garbling
I'm trying to build a quick Extension to format selected HTML source
into lines of JavaScript document.write(). So far, I'm using regex to
replace (.*)\n with "htmlOutput += \"$1\"\n" ... which is supposed to
provide the following sample output.
Select this in DW:
<table width="100%" border="0">
<tr>
.... and it becomes this:
htmlOutput += "<table width=\"100%\" border=\"0\">";
htmlOutput += " <tr>";
The regex is good (tested in another app), but Dreamweaver insisits on
replacing the source with this:
htmlOutput += "
<table width=\"100%\" border=\"0\">
";
htmlOutput += "
<tr>
";
.... (note the extra linebreaks surrounding the $1 content). The relevant
code in my Extension is here:
if (offsets[0] != offsets[1]) {
var theSelection = theDom.source.getText(offsets[0],offsets[1]);
// Format output
var re = /(.*)\n/g;
theSelection = theSelection.replace(re, "htmlOutput += \"$1\"\n");
theDom.insertHTML(theSelection, true);
}
In the past, I've used regex to replace a text version of the DOM
object, but this seems like it should be more direct. Any reason for the
extra line breaks?
David
stiller (at) quip (dot) net
"Luck is the residue of good design."
David Stiller Guest
-
regex replace
Hi. I've a requirement in regular exp.. I need to replace a pattern...can anyone help me out,... My input string is as below <img... -
RegEx replace?
Im looking for some method similar to what Dreamwear has for it's regular expression search/replace... it allows you to reference the found text with... -
RegEx? To replace URLs in a string
Hi, I have a lump of text which may or may not contain URLs, either with or without their http:// construct. I need to replace every instance... -
Regex, how do I replace quotation pairs into <LI> & </LI>?
Basically, my texts consists of normal text stream and some quotations. This is my text stream, and inside "this streams" there are some... -
search and replace using regex
You may want to start looking at some XML parsing modules, but assuming this is a quickie, I can point out that your problem is starting with the... -
Distefano Felice #2
Re: regex replace string garbling
Perahps the code is not like you expect it. The way you get written it shows
like to be this:
\r<table width="100%" border="0">\r\n
and maybe could be more appropriate this expression:
var re = /\r(.*)\r\n/g;
I can't say it for sure because I didn't check it on DW but you can give it
a try.
Felix
"David Stiller" <stiller-NO-SPAM-@quip.net> ha scritto nel messaggio
news:d5tt0f$2ot$1@forums.macromedia.com...> I'm trying to build a quick Extension to format selected HTML source
> into lines of JavaScript document.write(). So far, I'm using regex to
> replace (.*)\n with "htmlOutput += \"$1\"\n" ... which is supposed to
> provide the following sample output.
>
> Select this in DW:
>
> <table width="100%" border="0">
> <tr>
>
> ... and it becomes this:
>
> htmlOutput += "<table width=\"100%\" border=\"0\">";
> htmlOutput += " <tr>";
>
> The regex is good (tested in another app), but Dreamweaver insisits on
> replacing the source with this:
>
> htmlOutput += "
> <table width=\"100%\" border=\"0\">
> ";
> htmlOutput += "
> <tr>
> ";
>
> ... (note the extra linebreaks surrounding the $1 content). The relevant
> code in my Extension is here:
>
> if (offsets[0] != offsets[1]) {
> var theSelection = theDom.source.getText(offsets[0],offsets[1]);
> // Format output
> var re = /(.*)\n/g;
> theSelection = theSelection.replace(re, "htmlOutput += \"$1\"\n");
> theDom.insertHTML(theSelection, true);
> }
>
> In the past, I've used regex to replace a text version of the DOM
> object, but this seems like it should be more direct. Any reason for the
> extra line breaks?
>
>
> David
> stiller (at) quip (dot) net
> "Luck is the residue of good design."
>
>
Distefano Felice Guest
-
David Stiller #3
Re: regex replace string garbling
> The regex is good (tested in another app), but Dreamweaver insisits
Heh, well, the regex was only partially good. I needed to search for> on replacing the source with this:
(.*)\r\n instead. So much for confidence, eh? ;)
The other part of my problem was that, so far, I wasn't including the
<script> tag wrapper. With that in place, things got better.
David
stiller (at) quip (dot) net
"Luck is the residue of good design."
David Stiller Guest
-
David Stiller #4
Re: regex replace string garbling
> Perahps the code is not like you expect it. The way you get written
Yup! I had left out the \r. Thanks, Felix!> it shows like to be this:
> \r<table width="100%" border="0">\r\n
David
stiller (at) quip (dot) net
"Luck is the residue of good design."
David Stiller Guest



Reply With Quote

