Skip to content

Instantly share code, notes, and snippets.

@jenlampton
Last active June 28, 2019 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenlampton/df6e83ac426c34a8d25852d9c6ba71a5 to your computer and use it in GitHub Desktop.
Save jenlampton/df6e83ac426c34a8d25852d9c6ba71a5 to your computer and use it in GitHub Desktop.
// Center aligned content requires an additional wrapper to set
// text-align: center.
if ($align === 'center') {
// If the image has a caption
$caption = $node->getAttribute('data-caption');
if ($caption) {
// something like this, but in PHP
// element.replaceWith(figure);
// figure.add(element);
// figure.add(caption);
}
else {
// Get closest p parent.
while ($target->nodeName !== 'p') {
$target = $target->parentNode;
}
$p_attribute = $dom->createAttribute('class');
$p_attribute->value = 'centered-wrapper';
$target->appendChild($p_attribute);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment