This commit is contained in:
IGNY8 VPS (Salman)
2025-12-01 11:24:15 +00:00
parent 1eb25d1c47
commit 30b93e5715
2 changed files with 24 additions and 6 deletions

View File

@@ -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