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.

Comments

devin carlson’s picture

Status: Active » Needs review
StatusFileSize
new1022 bytes

The "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.

devin carlson’s picture

Status: Needs review » Fixed

Committed to 7.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nomorerice’s picture

Version: » 7.x-1.1

I 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);

proweb.ua’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Assigned: devin carlson » proweb.ua
Status: Closed (fixed) » Needs work

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag ... invalid in Entity, line: 1 в simple_table_of_contents_generate_table_of_contents() (рядок 108 із /var/www/sd/observer/public_html/sites/all/modules/simple_table_of_contents/simple_table_of_contents.module).

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: ID note already defined in Entity, line: 4422 в simple_table_of_contents_generate_table_of_contents() (рядок 108 із /var/www/sd/observer/public_html/sites/all/modules/simple_table_of_contents/simple_table_of_contents.module).

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: ID 14 already defined in Entity, line: 3320 в simple_table_of_contents_generate_table_of_contents() (рядок 108 із /var/www/sd/observer/public_html/sites/all/modules/simple_table_of_contents/simple_table_of_contents.module).

etc.

vadym.kononenko’s picture

I see cureent 7.x-1.1 version does not contain this patch. Addopted patch version is attached.

vadym.kononenko’s picture

Assigned: proweb.ua » Unassigned
Status: Needs work » Needs review

The last submitted patch, 1: convert-special-characters-1853196-1.patch, failed testing.