Currently any special characters get mangled during the table of contents generation process.
This occurs due to the fact that DOMDocument::loadHTML() is working with an incomplete HTML document (no <head>, <body>, etc.) which does not have an encoding specified so DOMDocument::loadHTML() uses its default setting of ISO-8859-1.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | simple_table_of_contents--special-characters-get-mangled-markup.patch | 872 bytes | vadym.kononenko |
| #1 | convert-special-characters-1853196-1.patch | 1022 bytes | devin carlson |
Comments
Comment #1
devin carlson commentedThe "cleanest" fix seems to be encoding all HTML entities, generating the table of contents and then decoding the entities. This avoids concatenating metatags into the node's body field, building a fake HTML page, etc.
A patch to implement the fix.
Comment #2
devin carlson commentedCommitted to 7.x-1.x.
Comment #4
nomorerice commentedI got same error as yours :
Warning: DOMDocument::createElement() [domdocument.createelement]: unterminated entity reference "&" , in simple_table_of_contents_generate_table_of_contents()
Patch: simple_table_of_contents.module Line 197
function simple_table_of_contents_generate_table_of_contents($html) {
...
// Iterate through the headings and build the table of contents
foreach ($headings as $node) {
$level = (int) $node->tagName[1];
-$name = $node->textContent;
+$name = htmlspecialchars($node->textContent);
Comment #5
proweb.ua commentedetc.
Comment #6
vadym.kononenko commentedI see cureent 7.x-1.1 version does not contain this patch. Addopted patch version is attached.
Comment #7
vadym.kononenko commented