Skip to content

Commit

Permalink
HPC-9974: Fix footnotes logic so that characters that are not valid X…
Browse files Browse the repository at this point in the history
…ML do not break text formatting
  • Loading branch information
berliner committed Dec 13, 2024
1 parent 89e8b3e commit 9960e1f
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static function updateFootnotes($html, $build) {

// Process the texts with footnotes.
foreach (iterator_to_array($dom->getElementsByTagName('gho-footnotes-text')) as $node) {
/** @var \DOMNode $node */
$id = $node->getAttribute('data-id');
$node_inner_html = gho_footnotes_get_inner_html($node);
$node_inner_html = preg_replace('/<!--(.|\s)*?-->\s*/', '', $node_inner_html);
Expand Down Expand Up @@ -74,6 +75,9 @@ public static function updateFootnotes($html, $build) {

// Update the footnote references and remove the containing div.
$node_inner_html = gho_footnotes_update_text($id, $node_inner_html, $references, $footnotes);
// We do some back and forth for special characters to prevent XML
// parsing errors.
$node_inner_html = htmlspecialchars_decode(htmlspecialchars($node_inner_html, ENT_DISALLOWED), ENT_XML1);
$fragment = $dom->createDocumentFragment();
// Note that we add a newline here. This is made to prevent a strange
// issue with the caption credits, that are sometimes appearing spaceless
Expand Down

0 comments on commit 9960e1f

Please sign in to comment.