Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Craigy

macrumors 6502
Original poster
Jan 14, 2003
403
48
New Zealand
OK - I love FCKEditor - but something is driving me a little crazy. I'm using it for one of our customers blog sites - They need to work in the source code view from time to time and find the 'compactness' of the code difficult to navigate.

FCKEditor always removes line breaks etc from the code. What I am looking for is the JS function / code that strips these spaces and change it so that code is formatted audtomatically like this:

<h1>Thtle</h1>

<p>Text</p>

<p>Text 2</p>

<hr>

<p>Text 3</p>

rather than:

<h1>Thtle</h1>
<p>Text</p>
<p>Text 2</p>
<hr>
<p>Text 3</p>

ie: putting an extra space between blocks.

Tried posting on the FCKEditor forum and Experts-Exchange with no joy - Anyone out there point me in the right direction?

Thanks in advance :)
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
Have you looked into Tidy?

I'm not sure why you're wanting to do this with JavaScript. If they're working on it in source code, it should be local right? Tidy is a nice thing for cleaning up code like this. Alternatively, you could use a scripting language to do it like Perl. I haven't used FCKEditor, though have run across it, so I don't know when it formats the code for you.

You might be able to apply some JavaScript regular expression goodness to help too.

PHP:
htmlcode = htmlcode.replace(/[\n]/g, "\n\n");
* That's a backslash n inside the [ ]. It got removed by the forum.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.