Forum closed. New forum available at http://community.wymeditor.org/

formatting of generated code

Support forum for WYMeditor.

formatting of generated code

Postby meter on Thu Feb 25, 2010 8:21 am

The code that WYMeditor is generating for me looks like:
Code: Select all
<h1>Foo</h1><p>Bar went to the store.</p><p>Baz stayed home.</p>


What I would like is:
Code: Select all
<h1>Foo</h1>
<p>Bar went to the store.</p>
<p>Baz stayed home.</p>


or even

Code: Select all
<h1>Foo</h1>
<p>Things Bar likes:</p>
<ol>
  <li>Baz</li>
  <li>Baz's cat</li>
</ol>


I am guessing that the reason that WYMeditor makes code like the former is because it simplifies code generation (in keeping with the "WYMeditor shall remain simple" principle) and arguably because it results in slightly more compact HTML deliverables.

Still, I am wondering if it's possible to generate anything like the latter.

-M
meter
 
Posts: 2
Joined: Thu Feb 25, 2010 8:11 am

Re: formatting of generated code

Postby mka on Thu Feb 25, 2010 9:03 am

It's not really an issue (of WYMeditor). As long as the editor outputs valid XHTML, you can post-process data anyway you want.

E.g. adding indent's using libxml or similar tool.
mka
 
Posts: 2
Joined: Thu Feb 25, 2010 8:14 am

Re: formatting of generated code

Postby meter on Fri Feb 26, 2010 12:56 pm

mka wrote:It's not really an issue (of WYMeditor).


Actually, it is. Hit the HTML button to hand tweak or insert some code and try to find the right place to do your edits. When the code is one huge megaline, navigating it is difficult. After-the-fact formatting (i.e., postprocessing) doesn't help here.

-M
meter
 
Posts: 2
Joined: Thu Feb 25, 2010 8:11 am

Re: formatting of generated code

Postby mr_lundis on Thu Apr 01, 2010 12:46 pm

meter wrote:
mka wrote:It's not really an issue (of WYMeditor).


Actually, it is. Hit the HTML button to hand tweak or insert some code and try to find the right place to do your edits. When the code is one huge megaline, navigating it is difficult. After-the-fact formatting (i.e., postprocessing) doesn't help here.

-M


Makes a perfect plugin! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: formatting of generated code

Postby rasa on Fri Oct 22, 2010 11:48 am

Formatted code can be achieved with the help of some regular expressions. I was also frustrated with this issue. This is how I figured it out for myself. It is not perfect but as this is a simple script the result is quite good. Feel free to use it.
The $content is your content you actually posting. You need to insert this BEFORE it is saved. There are some "bugs" (I called them so) which are solved in a way that an extra space is inserted after a closing tag and before a newline. Not doing this way the code is sometimes (depending on browsers, too) collapsed back to one line. This workaround is not exactly what I wanted but could not figure out nothing better. Hope this help. I use this a year or so with relatively good output in FF.


Code: Select all
    $content = $_POST['content'];

    $old = array (
        '/(?<=<\/h\d>)(?=<)/',                  //01. headings
        '/(?<=<\/div>)(?=<)/',                  //02. div
        '/(?<=<\/p>)(?=<[^\/])/',               //03. paragraph (/noscript exclusion)
        '/(<li>[^<]+)?(<[uo]l>)(?=<li>)/',      //04. nested or opening list  (<li>text)?<uol><li>
        '/(?<=<\/li>)(<\/[uo]l>)(?=<\/li>)/',   //05. nested list  </li></uol></li>
        '/(?<=<\/li>)(<\/[uo]l>)(?!<\/li>)/',   //06. list ending  </li></uol>(not</li>)
        '/(?<=<\/li>)(?=<li>)/',                //07. li
        '/(?<=<br \/>)(?=\S)/',                 //08. br
        '/(?<!br)(?<= \/>)(?=\S)/',             //09. img
        '/(?<=script>)(?=<)/',                  //10. script/noscript
        '/(?<=> \n)(?=<table)/',                //11. table opening [with extra space bug]
        '/(?<=>)(<caption>[^<]*)(?=<\/capt)/',  //12. caption
        '/(<tbody>)(<tr>)/',                    //13. tbody, tr [tbody is always added by wymeditor]
        '/(?<=<\/td>)(?=<td>)/',                //14. td
        '/<\/tr>(<tr>)/',                       //15. tr
        '/(<\/tr>)(<\/tbody>)(<\/table>)/'      //16. table ending
        );
    $new  = array (
        " \n",                                  //01. extra space
        " \n",                                  //02. extra space
        " \n",                                  //03. extra space
        "$1\n $2\n   ",                         //04.
        "\n $1\n   ",                           //05.
        "\n $1 \n\n",                           //06.
        "\n   ",                                //07. 3 spaces (li after li)
        "\n",                                   //08. new textline after a br
        " \n",                                  //09. extra space
        " \n",                                  //10. extra space
        "\n",                                   //11.
        " \n$1",                                //12.
        "\n $1\n $2 \n   ",                     //13.
        "\n   ",                                //14.
        "\n </tr>\n $1 \n   ",                  //15.
        "\n $1\n $2 \n$3 \n\n"                  //16.
        );
    $content = preg_replace($old, $new, $content);
rasa
 
Posts: 1
Joined: Thu Apr 23, 2009 11:27 am


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests