Content block: cancel div to p replacement

Permalink 3 users found helpful
Cheers,

Need some help with tweaking content block. I need to disable div to p replacement. Redactor official docs list 'replaceDivs' as option for that. I've added
replaceDivs: false
to Redactor call in add.php and edit.php in application/blocks/content/ but nothing changes, something still overrides added divs. Any ideas?

Thanks a million in advance for any hint!

 
Jupiter replied on at Permalink Best Answer Reply
Jupiter
hi gorillabrand,

please look at below link...
http://www.concrete5.org/community/forums/customizing_c5/a-way-to-r...
I hope this will help you

Thanks
jupiter
gorillabrand replied on at Permalink Reply
hi Jupiter!

Thanks a lot, but nope, this link relates to the pre-5.7 version which used TinyMCE editor. Now C5 uses Redactor byhttp://imperavi.com/redactor/.

Thanks,
gorillabrand
gorillabrand replied on at Permalink Reply
Jupiter, it helped!
I used logic from your link in redactor.js and it worked like charm!
Thank you!
Darragi replied on at Permalink Reply
Hi gorillabrand,

Can you post the solution please? because i have same problem.

That may help and save time for other people also.

Thanks in advance
Darragi replied on at Permalink Reply
Hi,

Found it!
Not as mentioned in official redactor doc, the correct option is:
convertDivs: false,


Hope that helps other

Thanks,
Darragi
craigrundle replied on at Permalink Reply
convertDivs:false,


did not work for me.

replaceDivs: false,


worked.
WillemAnchor replied on at Permalink Reply
WillemAnchor
you may also want to set:

linebreaks: true,
paragraphize: false,
aruben replied on at Permalink Reply
aruben
Hi gorillabrand,

Perhaps it's too late, but this can help someone else.

You need to customize the Redactor Editor to use breaklines instead of paragraphs.
After, it's possible to add the DIV tag inside using the html view.
But if you insert an element inside (text, image...), it breaks the DIV, except if the content of the DIV is inside P (ie: DIV P ... /P /DIV).
Or, we must use the linebreaks options (use BR instead of P). But with this last option, you can't use P tag, because all of them are converted into BR !
It's the same issue with SECTION tag or others.

Conclusion: use the HTML block instead of Redactor to add DIV, or use the grid (better).


If you want to use DIV inside Redactor, look at
https://gist.github.com/hissy/8da3e9ffe9f3935d1be8...
adding the WillemAnchor's comment:

1.Make application/src/Editor/RedactorEditor.php
2.Override editor binding from application/bootstrap/app.php

In file app.php, add:

Core::bindShared('editor', function() { 
   return new \Application\Src\Editor\RedactorEditor(); 
});


In file RedactorEditor.php, add:

<?php
namespace Application\Src\Editor;
class RedactorEditor extends \Concrete\Core\Editor\RedactorEditor
{
   protected function getEditor($key, $content = null, $options = array())
   {
      // Stop converting divs to paragraphs
      $options['replaceDivs'] = false;
      /*Don't use these 2 options, insert a P tag inside the DIV instead
      // Use line breaks <br> instead of paragraphs <p> when user presses Return key (because <p> is semantic)
      $options['linebreaks'] = true;
      // Marks up text with paragraphs, if it hasn't been marked up with paragraphs yet
      $options['paragraphize'] = false;   //=true if linebreaks=false
      */
      return parent::getEditor($key, $content, $options);

(tested with Redactor 10.0.9 and 10.2.1 - ie: C5 5.7.4.2 and 5.7.5.1)

I think it's better to use a specific theme page to add SECTION tags, the grid system to add DIV, with Redactor inside to put the text, instead of using DIV inside Redactor.

I hope this will help you.

Thanks,
ARuben
syedmushran replied on at Permalink Reply
Hi ARuben,

I was able to fix the problem of div tags being replaced with p tags. Now I have another problem, <span> tags in my code are being removed. Could you please help me with this?

Regards
Syed Mushran
aruben replied on at Permalink Reply
aruben
Hi,

For <span> tag, in my tests, they are not removed. So, perhaps you have changed the code and it breaks the span tag.
I also notice that it don't accept imbricated <span>: it remove one.

Perhaps, spending time with Redactor now is not a good idea: (https://github.com/concrete5/concrete5/issues/3293)
Redactor seem to be stay in v5.7 only.

Regards,
ARuben