Skip to content

Commit 5d910ff

Browse files
committed
Add an XML encoding declaration to load Gist content as UTF-8. Fixes #76
1 parent e3f260e commit 5d910ff

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

includes/class-gistpress.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ public function process_gist_html( $html, array $args ) {
462462
return $html;
463463
}
464464

465+
// Load the HTML as UTF-8.
466+
$html = '<?xml encoding="utf-8" ?>' . $html;
467+
465468
$dom = new DOMDocument();
466469
$dom->loadHTML( $html );
467470

@@ -519,6 +522,14 @@ public function process_gist_html( $html, array $args ) {
519522
$line->parentNode->removeChild( $line );
520523
}
521524

525+
// Remove the XML declaration.
526+
foreach ( $dom->childNodes as $node ) {
527+
if ( $node instanceof DOMProcessingInstruction ) {
528+
$dom->removeChild( $node );
529+
break;
530+
}
531+
}
532+
522533
$html = $dom->saveHTML();
523534

524535
// Restrict the line number display if a range has been specified.

0 commit comments

Comments
 (0)