📜 ⬆️ ⬇️

Compatibility with habra editor for MODx Evo

In the process of transferring my articles from Habra or sites to LiveStreet, I became confronted with the layout problem.
The editor of habr perceives hyphenation in the source text exactly as hyphenation, i.e. in HTML they will look like
<br> 

And all available editors for modx in edit mode do not perceive links and images, and the text will look like in the editor:

    : - , ,  , ,  . <a href="https://picasaweb.google.com/lh/photo/DWXbDrGSQrrqY2TJM_UhydMTjNZETYmyPJy0liipFm0?feat=embedwebsite"><img src="https://lh6.googleusercontent.com/-vrs2uZgIzqQ/UJPFgBkWr-I/AAAAAAAAKxg/FS0DcyCkW0w/s640/Samsung%2520Note%2520II-001.jpg" height="107" width="640" /></a> <habrcut text="      ?" /> <ul> <li><a href="#pack">  </a></li> <li><a href="#view">    </a></li> <li><a href="#screen"></a></li> <li><a href="#inside">,   </a></li> 



And if you insert text in edit mode, it will turn into text without hyphenation:
')
       ,    ,        "---",    .       ,    ,      MSP430  Wiring  BASCOM(        ,      ),      :! !<source lang="cpp"> #include <Servo.h> // Servo myservo1;// Servo myservo2; int x = 0; //  int y = 0; int z = 0; int w = 0; int g = 0; int h = 0; int q = 0; 


Which is also uncomfortable. No, you could of course set up a replacement in any text editor - / n to br, but the problem is that then we get two different versions of the text, which will result in problems with editing. Had to make a freelancer order a bicycle.

Plugin for automatic replacement of / n to br while saving text and replacing it back when editing it:
 global $content; $e = &$modx->Event; switch ($e->name) { case "OnDocFormPrerender": $content["content"]=trim(preg_replace("/\<br\>/i","\r\n",$content["content"])); //      break; case "OnBeforeDocFormSave": $content=preg_replace("/(\\\\r\\\\n)/","<br>",$content); //   $content=preg_replace("/(\\\\n)/","<br>",$content); $content=preg_replace("/(\\\\r)/","<br>",$content); //    $content=preg_replace("/\<\/li\>\s*(\<br\>)+\s*\<li/i","</li>\\\\r\\\\n<li",$content); $content=preg_replace("/\<ul\>\s*(\<br\>)+\s*\<li/i","<ul>\\\\r\\\\n<li",$content); $content=preg_replace("/\<\/li\>\s*(\<br\>)+\s*\<\/ul/i","</li>\\\\r\\\\n</ul",$content); $content=preg_replace("/\s*(\<br\>)+\s*\<ul/i","\\\\r\\\\n<ul",$content); $content=preg_replace("/\<\/ul\>\s*(\<br\>)+\s*/i","</ul>\\\\r\\\\n",$content);//      break; default : return; break; } 


Installation is common - Manage items - plugins - create a plugin.
Copy the code in the field, then go to the system events tab and mark OnBeforeDocFormSave and OnDocFormPrerender - run when you open and save the document.

Source: https://habr.com/ru/post/157187/


All Articles