|
Easy way to organize code (tags sorted by spaces)?
04-30-2009, 05:21 PM
|
Easy way to organize code (tags sorted by spaces)?
|
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
|
OK I have a project where the source code contains huge blocks of code with a few spaces in between the tags, for example:
HTML Code:
<table>
<tbody><tr> <td class="tableRightAlign">Goeie mτre. </td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Good morning.</td> </tr> <tr> <td class="tableRightAlign">Goeie middag.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Good afternoon.</td> </tr> <tr> <td class="tableRightAlign">Goeie naand.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Good evening.</td> </tr> <tr> <td class="tableRightAlign">Goeie nag.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Good night.</td> </tr> <tr> <td class="tableRightAlign">Totsiens.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Good bye.</td> </tr> <tr> <td class="tableRightAlign">My naam is _(Jacques)_ .</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">My name is _____ .</td> </tr> <tr> <td class="tableRightAlign">Waar kom u vandaan?</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Where do you come from?</td> </tr> <tr> <td class="tableRightAlign">Ek kom van _(Moskou)_ af.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">I come from ____ .</td> </tr> <tr> <td class="tableRightAlign">Ek gaan na Suid-Afrika toe.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">I am going to South Africa.</td> </tr> <tr> <td class="tableRightAlign">Wat is u naam?</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">What is your name?</td> </tr> <tr> <td class="tableRightAlign">Hoe gaan dit?</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">How are you doing?</td> </tr> <tr> <td class="tableRightAlign">Baie goed dankie en self?</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Well thanks and yourself?</td> </tr> <tr> <td class="tableRightAlign"> Nie te sleg nie dankie.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Not too bad thanks.</td> </tr> <tr> <td class="tableRightAlign">Verskoon my asseblief.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Pardon me please.</td> </tr> <tr> <td class="tableRightAlign">Hoe sκ 'n mens......?</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">How does one say. . . . .?</td> </tr> <tr> <td class="tableRightAlign">Mag ek Engels praat asseblief?</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">May I speak English please?</td> </tr> <tr> <td class="tableRightAlign">Nie te danke/Dis 'n plesier.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Only a pleasure.</td> </tr> <tr> <td class="tableRightAlign">Ek is jammer.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">I'm sorry.</td> </tr> <tr> <td class="tableRightAlign">Ken julle mekaar?</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Have you met? (Do you know each other?)</td> </tr> <tr> <td class="tableRightAlign">Dis heerlike weer.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">It's lovely weather.</td> </tr> <tr> <td class="tableRightAlign">Moenie so gaap nie.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Don't yawn like that.</td> </tr> <tr> <td class="tableRightAlign">Slaap lekker.</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Sleep tight.</td> </tr> <tr> <td class="tableRightAlign">Veels geluk! (met...)</td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">Congratulations! (with...)</td> </tr> <tr> <td class="tableRightAlign">Sterkte! </td> <td class="tableMiddleColumn"></td> <td class="tableLeftAlign">All the best!/Good luck! (meaning: "strength")</td> </tr> </tbody>
</table>
So I'm curious if it's possible to sort it easily without going through each and every tag break, editing the spaces and pressing enter each time, like I did for this one:
HTML Code:
<table>
<tbody>
<tr>
<td class="tableRightAlign">Goeie mτre.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Good morning.</td>
</tr>
<tr>
<td class="tableRightAlign">Goeie middag.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Good afternoon.</td>
</tr>
<tr>
<td class="tableRightAlign">Goeie naand.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Good evening.</td>
</tr>
<tr>
<td class="tableRightAlign">Goeie nag.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Good night.</td>
</tr>
<tr>
<td class="tableRightAlign">Totsiens.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Good bye.</td>
</tr>
<tr>
<td class="tableRightAlign">My naam is _(Jacques)_ .</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">My name is _____ .</td>
</tr>
<tr>
<td class="tableRightAlign">Waar kom u vandaan?</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Where do you come from?</td>
</tr>
<tr>
<td class="tableRightAlign">Ek kom van _(Moskou)_ af.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">I come from ____ .</td>
</tr>
<tr>
<td class="tableRightAlign">Ek gaan na Suid-Afrika toe.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">I am going to South Africa.</td>
</tr>
<tr>
<td class="tableRightAlign">Wat is u naam?</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">What is your name?</td>
</tr>
<tr>
<td class="tableRightAlign">Hoe gaan dit?</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">How are you doing?</td>
</tr>
<tr>
<td class="tableRightAlign">Baie goed dankie en self?</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Well thanks and yourself?</td>
</tr>
<tr>
<td class="tableRightAlign"> Nie te sleg nie dankie.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Not too bad thanks.</td>
</tr>
<tr>
<td class="tableRightAlign">Verskoon my asseblief.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Pardon me please.</td>
</tr>
<tr>
<td class="tableRightAlign">Hoe sκ 'n mens......?</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">How does one say. . . . .?</td>
</tr>
<tr>
<td class="tableRightAlign">Mag ek Engels praat asseblief?</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">May I speak English please?</td>
</tr>
<tr>
<td class="tableRightAlign">Nie te danke/Dis 'n plesier.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Only a pleasure.</td>
</tr>
<tr>
<td class="tableRightAlign">Ek is jammer.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">I'm sorry.</td>
</tr>
<tr>
<td class="tableRightAlign">Ken julle mekaar?</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Have you met? (Do you know each other?)</td>
</tr>
<tr>
<td class="tableRightAlign">Dis heerlike weer.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">It's lovely weather.</td>
</tr>
<tr>
<td class="tableRightAlign">Moenie so gaap nie.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Don't yawn like that.</td>
</tr>
<tr>
<td class="tableRightAlign">Slaap lekker.</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Sleep tight.</td>
</tr>
<tr>
<td class="tableRightAlign">Veels geluk! (met...)</td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">Congratulations! (with...)</td>
</tr>
<tr>
<td class="tableRightAlign">Sterkte! </td>
<td class="tableMiddleColumn"></td>
<td class="tableLeftAlign">All the best!/Good luck! (meaning: "strength")</td>
</tr>
</tbody>
</table>
I already tried wrapping the text, but that just changes it from one line to a large code block, you may have to copy and paste the first block to see what I mean.
I've got about 50 of these pages to do and just the first one was somewhat tedious.
I'm currently using notepad++, if it's possible with this program.
|
|
|
|
04-30-2009, 07:12 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
|
I would think all the extra spaces will be the same each time out.
Copy one example of that extra space and then do a search and replace. Search for the space you copied and replace it with a line break. That will probably fix most of the code.
I forget what Notepads search and replace is like, but I think it has enough to do this. If not plenty of other free text editors do.
|
|
|
|
04-30-2009, 07:24 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
|
The thing is though not all the tables are the same, some have different element properties and values, others have completely different data lengths. So not all the tables can be manipulated just the way one is (that I did to the first code block).
Notepad++ does have that feature though:
(Menu Bar) >> Search >> Replace
|
|
|
|
04-30-2009, 08:55 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 996
Location: Not positive
|
Do it in PHP!
PHP Code:
<?php $subject_str = '<table> <tbody><tr> <td class="tableRightAlign">Goeie mτre. </td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Good morning.</td> </tr> <tr> <td class="tableRightAlign">Goeie middag.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Good afternoon.</td> </tr> <tr> <td class="tableRightAlign">Goeie naand.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Good evening.</td> </tr> <tr> <td class="tableRightAlign">Goeie nag.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Good night.</td> </tr> <tr> <td class="tableRightAlign">Totsiens.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Good bye.</td> </tr> <tr> <td class="tableRightAlign">My naam is _(Jacques)_ .</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">My name is _____ .</td> </tr> <tr> <td class="tableRightAlign">Waar kom u vandaan?</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Where do you come from?</td> </tr> <tr> <td class="tableRightAlign">Ek kom van _(Moskou)_ af.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">I come from ____ .</td> </tr> <tr> <td class="tableRightAlign">Ek gaan na Suid-Afrika toe.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">I am going to South Africa.</td> </tr> <tr> <td class="tableRightAlign">Wat is u naam?</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">What is your name?</td> </tr> <tr> <td class="tableRightAlign">Hoe gaan dit?</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">How are you doing?</td> </tr> <tr> <td class="tableRightAlign">Baie goed dankie en self?</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Well thanks and yourself?</td> </tr> <tr> <td class="tableRightAlign"> Nie te sleg nie dankie.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Not too bad thanks.</td> </tr> <tr> <td class="tableRightAlign">Verskoon my asseblief.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Pardon me please.</td> </tr> <tr> <td class="tableRightAlign">Hoe sκ \'n mens......?</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">How does one say. . . . .?</td> </tr> <tr> <td class="tableRightAlign">Mag ek Engels praat asseblief?</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">May I speak English please?</td> </tr> <tr> <td class="tableRightAlign">Nie te danke/Dis \'n plesier.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Only a pleasure.</td> </tr> <tr> <td class="tableRightAlign">Ek is jammer.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">I\'m sorry.</td> </tr> <tr> <td class="tableRightAlign">Ken julle mekaar?</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Have you met? (Do you know each other?)</td> </tr> <tr> <td class="tableRightAlign">Dis heerlike weer.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">It\'s lovely weather.</td> </tr> <tr> <td class="tableRightAlign">Moenie so gaap nie.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Don\'t yawn like that.</td> </tr> <tr> <td class="tableRightAlign">Slaap lekker.</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Sleep tight.</td> </tr> <tr> <td class="tableRightAlign">Veels geluk! (met...)</td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">Congratulations! (with...)</td> </tr> <tr> <td class="tableRightAlign">Sterkte! </td> <td class="tableMiddleColumn">•</td> <td class="tableLeftAlign">All the best!/Good luck! (meaning: "strength")</td> </tr> </tbody> </table>';
$before = array("<", ">"); $after = array("<", ">"); $replace = str_replace($before, $after, $subject_str);
$before = array(" ", "</td>", "</tr>", "<tr>"); $after = array("", "</td><br />", "</tr><br />", "<tr><br />"); $replaceagain = str_replace($before, $after, $replace);
echo $replaceagain;
?>
Now that code alone will output a clean, well-sorted string. For your other content, use the Search >> Replace in Notepad++ and replace all occurrences of ' with \' . Once you've pasted your replaced code in the $subject_str variable, you should be ready to go.
- Steve
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
Last edited by stevej; 04-30-2009 at 09:21 PM..
|
|
|
|
04-30-2009, 11:57 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
|
I thought you wanted to replace all the spaces with a new line. If so I don't see why the search I described would be a problem.
|
|
|
|
05-01-2009, 12:32 AM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
|
Steve A:
I don't have full access to the server, it's for an internship I'm working on with only access to a few sections of the CMS (Typo3).
Steve B:
I meant that the spacing number was different. Some have 4 spaces, others have 7, etc.
BTW, how do you tell it to line break? (I tried replacing one example with <br />, and that's all it does, not the same as pressing enter.)
|
|
|
|
05-01-2009, 12:58 AM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 996
Location: Not positive
|
Quote:
Originally Posted by jamestl2
Steve A:
I don't have full access to the server, it's for an internship I'm working on with only access to a few sections of the CMS (Typo3).
|
That's okay, the code is for conversion purposes only. You're supposed to copy-and-paste what it outputs (or that's what I had in mind, anyway).
Quote:
Originally Posted by jamestl2
I meant that the spacing number was different. Some have 4 spaces, others have 7, etc.
|
What the code does is replace any occurrence of 2 spaces with nothing. So it'll work with 4 or 7.
Quote:
Originally Posted by jamestl2
BTW, how do you tell it to line break? (I tried replacing one example with <br />, and that's all it does, not the same as pressing enter.)
|
Can you specify?
- Steve
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
|
|
|
|
05-01-2009, 01:13 AM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
|
Quote:
Originally Posted by stevej
That's okay, the code is for conversion purposes only. You're supposed to copy-and-paste what it outputs (or that's what I had in mind, anyway).
|
Where do you suggest I test the conversion script then? Like I said, I don't have full server access.
Quote:
Originally Posted by stevej
Can you specify?
|
In Notepad++, all it does is replace the spaces with <br /> 's, it's not actually changing the format of the code.
I'm trying to make the code prettier in the source view, not what people see through their browsers.
|
|
|
|
05-01-2009, 01:23 AM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 996
Location: Not positive
|
Quote:
Originally Posted by jamestl2
Where do you suggest I test the conversion script then? Like I said, I don't have full server access.
|
Well, you could just install some local server like wamp to run the code...
Quote:
In Notepad++, all it does is replace the spaces with <br /> 's, it's not actually changing the format of the code.
I'm trying to make the code prettier in the source view, not what people see through their browsers.
|
Right. If you just run the code and then copy what it spits out, I think you'll be good to go.
- Steve
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
|
|
|
|
05-01-2009, 01:26 AM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
|
I do run some of my own websites  .
I suppose I'll take a look with it and see what I can do on my hosting account then.
EDIT: It worked, thanks.
Just curious though if it could work with just Notepad++.
Last edited by jamestl2; 05-01-2009 at 01:32 AM..
|
|
|
|
05-01-2009, 02:08 AM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 996
Location: Not positive
|
Glad it worked.
Quote:
Originally Posted by jamestl2
Just curious though if it could work with just Notepad++.
|
I'm not sure. I use Editplus, which (I think) is similar, so with some elaborate search and replace actions you might be able to clean it up.
- Steve
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
|
|
|
|
05-01-2009, 01:59 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 2,786
Name: Matt
Location: Irvine, CA
|
I think you can do it with just notepad++. You can search and replace with a regular expression as the search string and \n as the replace string (I think).
This is unrelated, but steve, I just noticed that the code in your sig has no effect:
PHP Code:
if($stevej == "helpful") { $talkupation + $user_power; }
There's no left side to that expression, so $talkupation never actually increases
PHP Code:
if($stevej == "helpful") { $talkupation = $talkupation + $user_power; }
OR
PHP Code:
if($stevej == "helpful") { $talkupation += $user_power; }

|
|
|
|
05-01-2009, 03:03 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 996
Location: Not positive
|
Haha, thanks for that, Nullpointer. I'm not too good with operators (I'm not to sure why).  
- Steve
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
|
|
|
|
05-01-2009, 06:38 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
|
Guess I'm late to the solution. I was going to add the /n, but nullpointer beat me to it.
James it sounds like you've got this worked out then. Cool.
|
|
|
|
05-05-2009, 01:31 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 120
Name: Kenson
Location: Washington, USA
|
Use Comments:
"
<!--Comment Here-->
"
Great for separating things!
|
|
|
|
05-05-2009, 06:40 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
|
Did you read the thread? Your suggestion indicates you didn't.
|
|
|
|
05-06-2009, 03:12 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 120
Name: Kenson
Location: Washington, USA
|
sorry, I was just suggesting that, it is really easy and good at seperating the tag areas...
|
|
|
|
05-06-2009, 10:04 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 2,141
Name: ...
Location: ...
|
Organizing code tutorial 101:
Memorize what you do, so you don't have to sort / space etc..etc..Sometime I may write it out in a notepad doc before I start because sometimes my memory serves me bad.
Note: That is only so I can refer to a 'master plan' before I start coding it
__________________
Made2Own
Last edited by Brian07002; 05-06-2009 at 10:06 PM..
|
|
|
|
05-07-2009, 08:35 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
|
@kcmartz - no worries and sorry if I came across harsh. Your advice is good. Just didn't apply here.
|
|
|
|
05-08-2009, 12:41 PM
|
Re: Easy way to organize code (tags sorted by spaces)?
|
Posts: 120
Name: Kenson
Location: Washington, USA
|
Ok, thanks!
*Didn't mean to be off-topic, just trying to help with tag separation*
|
|
|
|
|
« Reply to Easy way to organize code (tags sorted by spaces)?
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|