stripping off linefeeds in JavaScript, but only between ....

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

Tymerider
Posts: 1
Joined: Sat Apr 28, 2007 5:25 pm

stripping off linefeeds in JavaScript, but only between ....

Postby Tymerider » Sat Apr 28, 2007 7:09 pm

I would like to strip off the linefeeds on the JavaScript code between the <!-- and --> designators, so that the code between those designators is all on one line. As an example, my file looks like:

---------------------original code------------------------------------------
<SCRIPT TYPE="text/javascript">
<!--
var EMPTY_STRING = "";
function getEmptyString()
{
return EMPTY_STRING;
};

//-->
</SCRIPT>
<FORM NAME="KTM_DATA" METHOD=POST
onReset="return confirm('Do you really want to reset the form to the stock values?')">

<BODY onLoad="document.forms.KTM_DATA.favecolor.focus()">

favorite color:
<INPUT name="favecolor"><P>

<INPUT TYPE=SUBMIT VALUE="Submit">
<INPUT TYPE=RESET VALUE="Reset All Entries to Stock Values">
</FORM>

-----------------desired output--------------------------------------------------
<SCRIPT TYPE="text/javascript">
<!--
var EMPTY_STRING = "";function etEmptyString(){ return EMPTY_STRING;};
//-->
</SCRIPT>
<FORM NAME="KTM_DATA" METHOD=POST
onReset="return confirm('Do you really want to reset the form to the stock values?')">

<BODY onLoad="document.forms.KTM_DATA.favecolor.focus()">

favorite color:
<INPUT name="favecolor"><P>

<INPUT TYPE=SUBMIT VALUE="Submit">
<INPUT TYPE=RESET VALUE="Reset All Entries to Stock Values">
</FORM>

------------------end of output------------------------------------------------
I tried the following filters:

TextPipe Evaluation Edition

Filter Title: C:\Documents and Settings\removeLinefeeds.fll

Filter List
-----------
Filter options
| [ ] Log to file
| [X] Append to logfile
| Log filename: textpipe.log
| Threshold 500
|
|--Input from file(s)
| [ ] Confirm before processing each file
| [ ] Confirm before processing read/only files
| [ ] Delete input files after processing
| Skip binary files
| Sample size 100 characters
|
|--Restrict to between tags <script>...</script>
| | [ ] Include text
| | [ ] Match case
| | Max size: 65536
| |
| +--Restrict to lines NOT matching [^<SCRIPT]
| | [ ] Include line numbers
| | [ ] Include filename
| | [ ] Match case
| | [ ] Count matches
| | Pattern type: 0
| | Context before: 0
| | Context after: 0
| |
| +--Restrict to lines NOT matching [^</SCRIPT]
| | [ ] Include line numbers
| | [ ] Include filename
| | [ ] Match case
| | [ ] Count matches
| | Pattern type: 0
| | Context before: 0
| | Context after: 0
| |
| +--Restrict to lines NOT matching [^<!--]
| | [ ] Include line numbers
| | [ ] Include filename
| | [ ] Match case
| | [ ] Count matches
| | Pattern type: 0
| | Context before: 0
| | Context after: 0
| |
| +--Restrict to lines NOT matching [^//-->]
| | [ ] Include line numbers
| | [ ] Include filename
| | [ ] Match case
| | [ ] Count matches
| | Pattern type: 0
| | Context before: 1
| | Context after: 0
| |
| +--Perl pattern [\n] with [ ]
| [X] Match case
| [ ] Whole words only
| [ ] Case sensitive replace
| [ ] Prompt on replace
| [ ] Skip prompt if identical
| [ ] First only
| [ ] Extract matches
| Maximum text buffer size 4096
| [ ] Maximum match (greedy)
| [ ] Allow comments
| [X] '.' matches newline
| [ ] UTF-8 Support
|
+--Output to file(s)
[ ] Only update date on changed files
[ ] Append mode
[X] Change extension to: .js
[ ] Open output file
Only output modified files

Files List
----------
C:\Documents and Settings\simpleMailToFormWithCRs.html

---------but with that filter set I get the following output --------------
<SCRIPT TYPE="text/javascript"> <!--
var EMPTY_STRING = ""; function getEmptyString() { return EMPTY_STRING; }; //-->
</SCRIPT>
<FORM NAME="KTM_DATA" METHOD=POST
onReset="return confirm('Do you really want to reset the form to the stock values?')">

<BODY onLoad="document.forms.KTM_DATA.favecolor.focus()">

favorite color:
<INPUT name="favecolor"><P>

<INPUT TYPE=SUBMIT VALUE="Submit">
<INPUT TYPE=RESET VALUE="Reset All Entries to Stock Values">
</FORM>
---------------It;s close, but what I want is ----------------------------
<SCRIPT TYPE="text/javascript">
<!--
var EMPTY_STRING = ""; function getEmptyString() { return EMPTY_STRING; };
//-->
</SCRIPT>
<FORM NAME="KTM_DATA" METHOD=POST
onReset="return confirm('Do you really want to reset the form to the stock values?')">

<BODY onLoad="document.forms.KTM_DATA.favecolor.focus()">

favorite color:
<INPUT name="favecolor"><P>

<INPUT TYPE=SUBMIT VALUE="Submit">
<INPUT TYPE=RESET VALUE="Reset All Entries to Stock Values">
</FORM>

-------------------------------------------------------------------------
I.e., the <!-- and --> should remain on their own lines.

I've tried a bunch of different ways and can't seem to make that happen. What am I doing wrong?

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Postby DataMystic Support » Wed May 02, 2007 5:53 pm

All you need is this:

Restrict to between tags <script>...</script>
| [ ] Include text
| [ ] Match case
| Max size: 65536
|
+--Perl pattern [\r\n] with [ ]
[ ] Match case
[ ] Whole words only
[ ] Case sensitive replace
[ ] Prompt on replace
[ ] Skip prompt if identical
[ ] First only
[ ] Extract matches
Maximum text buffer size 4096
[ ] Maximum match (greedy)
[ ] Allow comments
[X] '.' matches newline
[ ] UTF-8 Support
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: No registered users and 5 guests