sad
This commit is contained in:
@@ -27,22 +27,25 @@ function igny8_parse_content_sections($content) {
|
||||
$dom = new DOMDocument('1.0', 'UTF-8');
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
// Load HTML with proper encoding
|
||||
$dom->loadHTML('<?xml encoding="UTF-8">' . $content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
// Wrap content in a div to ensure proper parsing
|
||||
$wrapped_content = '<div>' . $content . '</div>';
|
||||
$dom->loadHTML('<?xml encoding="UTF-8">' . $wrapped_content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
libxml_clear_errors();
|
||||
|
||||
$intro_html = '';
|
||||
$sections = [];
|
||||
$current_section = null;
|
||||
|
||||
// Get body node
|
||||
$body = $dom->getElementsByTagName('body')->item(0);
|
||||
if (!$body) {
|
||||
// Get the wrapper div
|
||||
$xpath = new DOMXPath($dom);
|
||||
$nodes = $xpath->query('//div/*');
|
||||
|
||||
if ($nodes->length === 0) {
|
||||
return ['intro' => $content, 'sections' => []];
|
||||
}
|
||||
|
||||
// Iterate through all child nodes
|
||||
foreach ($body->childNodes as $node) {
|
||||
foreach ($nodes as $node) {
|
||||
// Check if node is an H2 heading
|
||||
if ($node->nodeName === 'h2') {
|
||||
// Save previous section if exists
|
||||
|
||||
Reference in New Issue
Block a user