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

Comments

AlexisWilke’s picture

Status: Active » Needs review
StatusFileSize
new1.35 KB

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

MichaelT’s picture

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!

AlexisWilke’s picture

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

MichaelT’s picture

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

nhoeller’s picture

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

AlexisWilke’s picture

StatusFileSize
new1.42 KB

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

AlexisWilke’s picture

StatusFileSize
new1.35 KB

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

AlexisWilke’s picture

StatusFileSize
new1.32 KB

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

mabuweb’s picture

I use Collapsible Text with TinyMCE and just applied your patch.
It works fine also for TinyMCE.
Thanks.

afrizen’s picture

I just got Collapsible Text working with TinyMCE after applying the patch manually as well.
Much appreciation.

~afrizen->

iva2k’s picture

subscribing

epersonae2’s picture

subscribe.

Hawkcode’s picture

Hi,

I've looked at the example and there are a couple things I don't understand.

1. How do you Put your own text on the collapse like, replacing "Use the arrow to expand or collapse this section"

2. How do you make it start collapsed rather than open.

Thanks

Richard S Albrecht

AlexisWilke’s picture

Hawkcode,

First code section as posted by andreiashu, without the <p> tags.

Thank you.
Alexis

Hawkcode’s picture

OK but how do you start it in the collapsed state?

Is it possible?

Rich

AlexisWilke’s picture

[collapse collapsed]

saepl’s picture

subscribe. Will this be committed to the module?

AlexisWilke’s picture

I don't think the current maintainer maintains this module... 8-}

Alexis

pukku’s picture

It's more like I maintain in waves. There are long periods where I'm running as fast as I can to do everything that needs to be done for my job, and every few (for large values of few), I get around to going through the queues and fixing things...

I'll try to look at this shortly, but I'm still upgrading sites from 5 to 6...

Ricky

pooneil’s picture

Assigned: Unassigned » pooneil
Status: Needs review » Active

Hi all,

I am a new co-maintainer of this module. I'm going to experiment with this and hopefully get some version of it in the next release of this. I see a few of you had luck with one of the patches (I'm not sure which one for some replies). The one I'm currently looking at is "collapse_text-6.x-FCKeditor-4.patch". If anyone knows of any issues with that particular one, please let me know.

Regards,
Anthony

AlexisWilke’s picture

Hi pooneil,

That sounds like the good one 8-)

I also noticed some problems/clashes with the tableofcontents module. An anchor within a collapsed text area cannot be found by a browser (it is hidden.) I have been wondering how could we fix that?!

One last one... if a user misses marking a page teaser end point, and there is just a [collapse] tag (the [/collapse] is cut out) then you see the tag as is. (It is not removed.)

A sample would be something like this:

Testing...
[collapse]
test here
<!--break-->
end of collapsed text
[/collapse]
end of page.

I guess that should be another issue, but anyway... 8-}

Thank you.
Alexis

pukku’s picture

If tableofcontents is using javascript, I have no good solution. But if it is not using Javascript, you should change the order of the filters to have tableofcontents first.

AlexisWilke’s picture

pukku,

I think that the problem with the table of contents is mainly a problem with the browsers. Whenever I click on a link such as this_page#this_header, it does not work if #this_header is inside a closed (collapsed) fieldset.

I'm not too sure whether it should be fixed here or in the table of contents. The problem would appear for any module that uses collapse text and not just the table of contents. And I think it could be quite complicated to make such a thing work (i.e. review all the links, check whether some of them direct you inside a potentially collapsed fieldset, if so, replace with a JS that will first open the fieldset, then go to the anchor.

Thank you.
Alexis

pooneil’s picture

I just committed patch http://drupal.org/files/issues/collapse_text-6.x-FCKeditor-4.patch to the module. This will be available in the next release.

tallsimon’s picture

When will the next release be? I can't see a dev version... I think most installations now use wysiwyg so this feature is quite important!

pooneil’s picture

Sorry for the long delay in getting back to this! I've just committed changes that take care of the teaser issue as well as add support for escaping (so you can do \[collapse...] and it will show up verbatim). After I finish going through the rest of the queue I'll create a new version for testing.

~Anthony

Renee S’s picture

@pooneil,

Where are the changes committed?! The last dev release says 2008 :(

pooneil’s picture

Hi All,

You should be able to see a new version (beta) as 6.x-2.0-beta1. I just created it. It should handle the teaser issue (it just removes any leftover tags after processing which will handle the case where the teaser cuts off closing tags, etc.). It also will suppress "p" tags which should handle most WYSIWYG editors (but I haven't gotten to test most of them). Give it a test and let me know how it works for you.

Regards,
Anthony

pooneil’s picture

Status: Active » Closed (fixed)