Web Analytics Made Easy -
StatCounter :: removing tab spaces from code :: - CodingForum

Announcement

Collapse
No announcement yet.

:: removing tab spaces from code ::

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • :: removing tab spaces from code ::

    hi peeps - in the html 2 jscript converter in my sig i cant get the function to remove \r (tab) spaces

    any ideas:

    Code:
    <html>
    <title>HTML - JAVASCRIPT CONVERTER</title>
    <style type="text/css">
    <!--
    input {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #333333; border:1px solid #333333; width:160px; padding-top:2px}
    textarea {width:95%; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #333333; background-color:#FFFFFF; padding:5px; border:1px solid #333333; height:55%}
    p {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #333333}
    -->
    </style>
    
    <script language="JavaScript">
    <!--
    
    function writeCode(html,syntax)
    {
     var code="var code=\"";
    
     while (html.indexOf("  ")!=-1)
     html=html.split("  ").join(" ");
    
     html=html.split("\\").join("\\\\");
     html=html.split("/").join("\\/");
     html=html.split("\"").join("\\\"");
     html=html.split("\r\r").join("\r");
     html=html.split("\r").join("");
     html=html.split("\n\n").join("\n");
     if (syntax && syntax=="expanded") code+=html.split("\n").join("\\n\";\ncode+=\"");
     else code+=html.split("\n").join("\\n");
     code+="\";\n\ndocument.write(code)";
    
     document.html.source.value=code;
     document.html.convert.value=":: done ::";
     document.html.convert2.value=":: done ::";
     document.html.convert.onclick=null;
     document.html.convert2.onclick=null;
    }
    
    function ctrlA(el) {
    with(el){
    focus(); select() 
    }
    if(document.all){
    txt=el.createTextRange()
    txt.execCommand("Copy") 
    window.status='Selected and copied to clipboard!'
    document.html.clipboard.value=":: copied ::";
    }
    else window.status='Press ctrl-c to copy the text to the clipboard'
    setTimeout("window.status=''",3000)
    } 
    //-->
    </script>
    </head>
    
    <body bgcolor="#dddddd" onLoad="document.html.source.focus()">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="33%">&nbsp;</td>
        <td width="34%"><img src="img/html2javascript.gif" width="449" height="70"></td>
        <td width="33%" valign="bottom"> 
          <p>version 2.3<br />
            updated 17.04.02</p>
        </td>
      </tr>
    </table>
    <form name="html">
      <div align="center">
        <textarea name="source" class="box" cols="60" rows="17"></textarea>
        <br>
        <br />
        <input type="button" name="convert" value=":: convert (compact) ::" onClick="writeCode(document.html.source.value)">
    	<input type="button" name="convert2" value=":: convert (expanded)  ::" title="editor mode" onClick="writeCode(document.html.source.value,'expanded')">
        <input type="button" name="reset" value=":: reset ::" onClick="self.location.href=self.location.href">
        <input type="button" name="clipboard" value=":: copy to clipboard ::" onClick="ctrlA(document.html.source)">
    	  </div>
    </form>
    <p align="center">:: html2javascript converter by babelfish - based on code created by jopie ::</p>
    thanks!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    \r is a carriage return. \t is a tab. i'm thinking that's your problem.

    by the way, i've meant to suggest it before, but forgotten. if you wrap the html in single qoutes ( ' ), then you don't have to escape the double quotes.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      erm, tried that and it dont work

      any ideas?

      and i didnt change the " and ' cos im carp @ jscript

      although if that was an offer i will gladly accept
      "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

      Comment


      • #4
        that was my only idea. i do know for a fact though, that tab is \t, and not \r. i double checked the Guide on that.

        i got a couple of projects right now, but later, if you want, i'll take a look at helping you switch the quotes around.
        bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

        i am a loser geek, crazy with an evil streak,
        yes i do believe there is a violent thing inside of me.

        Comment


        • #5
          i might hold you to that and trying to workaround the document.write and style= NS4.7 bug
          (try to get document.write (*style=*) to work )
          "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

          Comment


          • #6
            ok, i did the following to your code. i haven't had the chance to test it at all, so don't throw what you have away in favor of this.

            i changed it to use the replace() method of Strings, instead of the split/join combo you had. also, i tried changing the quote marks around. the places where i changed it are in red. supposing those changes work, you could delete the line in bold, as unnecessary.

            hope this helps.

            Code:
            function writeCode(html,syntax)
            {
             var code="var code='";
            
             while (html.indexOf("  ")!=-1) {
              html.replace(/\u0020\u0020/g," ");
             }
            
             html.replace(/\\/g,"\\\\");
             html.replace(/\//g","\\/");
             html.replace(/\"/g,"\\\"");
             html.replace(/\t\t/g,"");
             html.replace(/\n\n/g,"\n");
             if (syntax && syntax=="expanded") { code+=html.replace(/\n/g,"\\n';\ncode+='"); }
             else { code+=html.replace(/\n/g,"\\n"); }
             code+="';\n\ndocument.write(code)";
            
             document.html.source.value=code;
             document.html.convert.value=":: done ::";
             document.html.convert2.value=":: done ::";
             document.html.convert.onclick=null;
             document.html.convert2.onclick=null;
            }
            bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

            i am a loser geek, crazy with an evil streak,
            yes i do believe there is a violent thing inside of me.

            Comment


            • #7
              that throws an error
              "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

              Comment

              Working...
              X