Skip to content

Instantly share code, notes, and snippets.

@colinodell
Created March 10, 2016 16:29
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 colinodell/cef401b8a8cb1268a991 to your computer and use it in GitHub Desktop.
Save colinodell/cef401b8a8cb1268a991 to your computer and use it in GitHub Desktop.
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