FCKEditor: Format of the source code

Discussion in 'Web Design and Development' started by Craigy, Jul 13, 2008.

  1. Craigy macrumors 6502

    Joined:
    Jan 14, 2003
    Location:
    New Zealand
    #1
    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 :)
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    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.
     

Share This Page