Update Post.php
This commit is contained in:
@@ -152,29 +152,36 @@ public function getHtmlBodyAttribute()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Modify the DOM by wrapping the <img> tags inside a <figure> and adding the desired structure
|
// Modify the DOM by wrapping the <img> tags inside a <figure> and adding the desired structure
|
||||||
$crawler->filter('img')->each(function (Crawler $node) {
|
$crawler->filter('img')->each(function (Crawler $node) {
|
||||||
$imgElement = $node->getNode(0);
|
$imgElement = $node->getNode(0);
|
||||||
|
|
||||||
|
// Update the class of the <img>
|
||||||
|
$existingClasses = $imgElement->getAttribute('class');
|
||||||
|
$newClasses = 'img-fluid rounded-2 shadow-sm mb-2';
|
||||||
|
$updatedClasses = ($existingClasses ? $existingClasses.' ' : '').$newClasses;
|
||||||
|
$imgElement->setAttribute('class', $updatedClasses);
|
||||||
|
|
||||||
|
// Create a new <figure> element
|
||||||
|
$figureElement = new \DOMElement('figure');
|
||||||
|
$imgElement->parentNode->insertBefore($figureElement, $imgElement);
|
||||||
|
|
||||||
|
// Move the <img> inside the <figure>
|
||||||
|
$figureElement->appendChild($imgElement);
|
||||||
|
$figureElement->setAttribute('class', 'image');
|
||||||
|
|
||||||
|
// Create a new <footer> element inside <figure> without directly setting its content
|
||||||
|
$footerElement = $imgElement->ownerDocument->createElement('footer');
|
||||||
|
$figureElement->appendChild($footerElement);
|
||||||
|
|
||||||
|
// Add the content to <footer> using createTextNode to ensure special characters are handled
|
||||||
|
$footerText = $imgElement->ownerDocument->createTextNode($imgElement->getAttribute('alt'));
|
||||||
|
$footerElement->appendChild($footerText);
|
||||||
|
|
||||||
|
// Set the class attribute for <footer>
|
||||||
|
$footerElement->setAttribute('class', 'image-caption');
|
||||||
|
});
|
||||||
|
|
||||||
// Update the class of the <img>
|
|
||||||
$existingClasses = $imgElement->getAttribute('class');
|
|
||||||
$newClasses = 'img-fluid rounded-2 shadow-sm mb-2';
|
|
||||||
$updatedClasses = ($existingClasses ? $existingClasses.' ' : '').$newClasses;
|
|
||||||
$imgElement->setAttribute('class', $updatedClasses);
|
|
||||||
|
|
||||||
// Create a new <figure> element
|
|
||||||
$figureElement = new \DOMElement('figure');
|
|
||||||
$imgElement->parentNode->insertBefore($figureElement, $imgElement);
|
|
||||||
|
|
||||||
// Move the <img> inside the <figure>
|
|
||||||
$figureElement->appendChild($imgElement);
|
|
||||||
$figureElement->setAttribute('class', 'image');
|
|
||||||
|
|
||||||
// Create a new <footer> element inside <figure>
|
|
||||||
$footerElement = new \DOMElement('footer', $imgElement->getAttribute('alt'));
|
|
||||||
$figureElement->appendChild($footerElement);
|
|
||||||
$footerElement->setAttribute('class', 'image-caption');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add Bootstrap 5 styling to tables
|
// Add Bootstrap 5 styling to tables
|
||||||
$crawler->filter('table')->each(function (Crawler $node) {
|
$crawler->filter('table')->each(function (Crawler $node) {
|
||||||
|
|||||||
Reference in New Issue
Block a user