Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adding 'dir' attribute to all paragraphs (UNTESTED)
<?php
// TODO: Set your "namespace" and "use" statements here
// Also see this documentation: http://commonmark.thephpleague.com/customization/abstract-syntax-tree/#document-processor
class ParagraphDirProcessor implements DocumentProcessorInterface
{
public function processDocument(Document $document)
{
$walker = $document->walker();
while ($event = $walker->next()) {
$node = $event->getNode();
// Only stop at Paragraph nodes when we first encounter them
if (!($node instanceof Paragraph) || !$event->isEntering()) {
continue;
}
$node->data['attributes']['dir'] = 'rtl';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.