Closed (fixed)
Project:
Table of Contents
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
2 Dec 2009 at 23:00 UTC
Updated:
17 Dec 2009 at 15:30 UTC
Jump to comment: Most recent file
Sometimes the Table of Contents creation fails depending on the markup in the node. The failure is caused by a newline preceeding the closing header tag:
THIS WORKS:
<h2>Alpha</h2>
<h2>Bravo</h2>
<h3>Bravo 1</h3>
<h3>Bravo 2</h3>
<h2>Charlie</h2>
THIS DOES NOT WORKS:
<h2>Alpha
</h2>
<h2>Bravo
</h2>
<h3>Bravo 1
</h3>
<h3>Bravo 2
</h3>
<h2>Charlie
</h2>
The parsing code needs to be modified. The regex being used to parse the header tag needs to include newline characters as part of the expression.
Some editors and users will insert newlines before closing tags. This is well-formed HTML/XHTML, and therefore should be correctly parsed. The current code fails silently.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | tableofcontents.pages_.inc_.patch | 464 bytes | stephen.moz |
| #2 | toc200912021853.patch | 619 bytes | stephen.moz |
Comments
Comment #1
stephen.moz commentedActually, it appears this problem is more general than the title suggests. I will create a patch that handles this.
Comment #2
stephen.moz commentedHere is a patch. This fixes the problem by modifying the replacement regex. Now the user can add newlines before and after the header tags without breaking the auto-generated TOC.
To verify the patch, create a node with the following markup, both before and after the patch:
Before applying the patch, only the header "Alpha" shows up in the auto-generated table of contents. After applying the patch, all three headers show up in the auto-generated table of contents.
Comment #3
stephen.moz commentedSorry, the previous attachment is the wrong file for the patch, see this one instead.
Comment #4
AlexisWilke commentedHi smosley,
Thank you for taking the time to post a patch!
I'd rather use the 's' modifier so the '.' character includes the new line character. As I was at it, I added the 'i' modifier even though it means it will accept (and deal somewhat improperly) the [collapse] tags in uppercase.
More info: http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php
I wrote a test here.
The -dev will have the fix within the next 12h.
Alexis Wilke
Comment #5
AlexisWilke commentedBtw, you're using the wrong editor... 9-)
FCKeditor removes those newline characters for you. (in that example, I turned off the editor.)
Comment #6
stephen.moz commentedThat makes sense. I think I've gotten in the habit of using character classes because not all of the languages I work with on a regular basis have the Perl Regex Engine available. Thus, the Perl-specific modifiers mean I have to change code if I want to port a complex regex to a non-PCRE-supporting language.
I like your additional point on the editor choice though, but this issue came up in a "shared" environment where it's a pain to try to get people to consider alternate tools or approaches unless it's something they think they want on their own. I actually prefer using Firefox + "It's all Text" + a regular desktop editor/IDE to make node edits, since you can run macros, create snippets and do all sorts of things that are still just too cumbersome for an in-browser WYSIWYG. That's what I had been using to deal with the whitespace issue.
But then, not everyone dances to the same beat. It was easier to just offer the patch. :)
At least I am using the right Table of Contents module ;)
Thanks a lot Alexis!