Make collapsible_text play nice with WYSIWYG editors
andreiashu - June 25, 2009 - 10:49
| Project: | Collapsible Text |
| Version: | 6.x-1.1 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
If you use a WYSIWYG editor with collapse_text the output won't be valid HTML.
This happens because most of these editors will wrap your [collapse] tags in paragraphs.
So for example your WYSIWYG editor will output something like this:
<p>[collapse collapsed]</p>
<h2>Header text</h2>
<p>Lorem ipsum etc.</p>
<p>[/collapse]</p>then collapse text will replace known tags with fieldsets and it will output something like this (note the
<p>s around opening and closing fieldsets):<p><fieldset class=" collapsible collapsed"><legend>Header test</legend><div></p>
<h2>Header text</h2>
<p>Lorem ipsum etc.</p>
<p></div></fieldset></p>I altered the pattern for the preg_match to take into consideration those (optional) extra paragraphs.
Note that the pattern already supports different versions of what an editor could output :
<p>[/collapse]</p>
<p>[/collapse][collapse collapsed]</p>
I tested this in FCKeditor only. More testing is needed in BUeditor and TinyMCE and other editor.
Cheers
| Attachment | Size |
|---|---|
| collapse_text_wysiwyg.patch | 1.94 KB |

#1
I use FCKeditor and have the same problem. Also I don't see the need for supporting spaces and newlines after the <p>, I think it would be a good idea to skip attributes. I have my own patch for that purpose.
Also, I do not need to fix the matches # as I use the (?:...) syntax to skip the useless paragraph tags.
Thank you.
Alexis Wilke
#2
I can’t get collapsible text to work properly!!! The text won’t stay under the header. Please see what I mean – I have created an example here: http://tinyurl.com/nw2utt
I have just pasted both the pieces of code in. (I am using FCKEditor so wonder if this is what you describe above). Is this what this patch would solve? If so, please can you tell me what I have to do with it?
Your help is greatly appreciated!
#3
Hi MichaelT,
Yes. You would need to patch your version of collapse text to work with FCKeditor. It looks very much the way I had on my site.
Btw, you can see my page here: http://linux.m2osw.com/booting
It includes the tableofcontents module for the table of content which I first thought was the problem.
Look here to know how to patch:
http://drupal.org/patch/apply
You can also do it by hand with a text editor...
Thank you.
Alexis
#4
L.E.G.E.N.D. ! Thank-you. It works perfectly. I changed the code with a text editor by just putting in the bits with a "+" in your code and deleting the "-" bits. Amazingly that crude process worked first time. Thank you very much for your help
#5
Alexis, I am confused. I am running Drupal 6.13 and FCKeditor 2.6.4. I installed the Collapsible text module, edited the appropriate Input formats profile, enabled the Collapse text filter and then rearranged it to come after HTML corrector (http://drupal.org/node/489990). I applied your patch and also tried the original collapse_text_wysiwyg.patch but still see the paragraph tags inserted around the [collapse] tags. I re-edited the document using the plain text editor, removed the paragraph tags between patches and re-saved. Any ideas what I might be missing?
thanks, Norbert
#6
Everyone,
You may want to take note of the following bug which is beyond Drupal since it is a PHP or PCRE bug, but has an impact on this module:
http://linux.m2osw.com/pcre_php_s_modifier_bug
Now, Norbert, my patch is not the one you mention. Look at #2 or use the one in this post (which I recommend! — NOT RECOMMENDED ANYMORE, please use version 3 below!) The problem you have could be from the fact that your <p> paragraphs include attributes (not supported by #1). If they did not have attributes when you edited without the WYSIWYG editor, then there is another problem I guess...
Let us know how this newer patch works for you.
Thank you.
Alexis Wilke
#7
Okay! I found a fix for my patch. The P tag attributes can be read using [^>] instead of . (period). That way, the regular expression is not considered too complex and it works. This also means we can keep the /smx modifiers.
There is a new patch.
Thank you.
Alexis Wilke
#8
Someone is going to kill me 8-)
I noticed another small problem. The way it was written it could appear in any tag that start with <p such as P, PARAM and PRE. Although it probably does not matter right now, it could be a problem long term and it could be a problem if you have some sub-XML in there (i.e. with a namespace that starts with a P.)
So... there is yet another patch.
Sorry for the trouble.
Alexis Wilke
#9
I use Collapsible Text with TinyMCE and just applied your patch.
It works fine also for TinyMCE.
Thanks.
#10
I just got Collapsible Text working with TinyMCE after applying the patch manually as well.
Much appreciation.
~afrizen->