Skip to content

Commit 38ae419

Browse files
committed
Prevent <figure> in <p>
1 parent 1e73fd6 commit 38ae419

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/HtmlConverter.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,29 @@ public static function convert($json, $parent, array $options = [])
9797
$html = smartypants($html);
9898
}
9999

100+
// Unwrap block elements from paragraphs
101+
$html = static::unwrapBlockElements($html);
102+
100103
return $html;
101104
} catch (\Exception) {
102105
return '';
103106
}
104107
}
108+
109+
/**
110+
* Unwrap block elements from paragraphs
111+
* Fixes invalid nesting when KirbyTags create block elements inside paragraphs
112+
* @param string $html HTML content to process
113+
* @return string Processed HTML with unwrapped block elements
114+
*/
115+
private static function unwrapBlockElements($html)
116+
{
117+
// Match <p> tags containing only block elements (figure, video, audio)
118+
// The pattern captures the block element and its content
119+
return preg_replace(
120+
'/<p>\s*(<(?:figure|video|audio)\b[^>]*>.*?<\/(?:figure|video|audio)>)\s*<\/p>/s',
121+
'$1',
122+
$html
123+
);
124+
}
105125
}

0 commit comments

Comments
 (0)