/**
  * @param ElementInterface $element
  *
  * @return string
  */
 public function handleTagImg(EventInterface $event, ElementInterface $element)
 {
     // Should mutate all images and stop propagation
     if (function_exists('cloudinary_url')) {
         $src = $element->getAttribute('src');
         $width = $element->getAttribute('width');
         $height = $element->getAttribute('height');
         $sizes = $this->generateSizes();
         $srcset = $this->generateSrcset($src);
         $urlConfig = ['width' => 400, 'height' => 225, 'crop' => 'limit', 'sign_url' => true, 'type' => 'fetch', 'effect' => 'sharpen'];
         if ($width < 100 || $height < 100) {
             $width = $urlConfig['width'];
             $height = $urlConfig['height'];
         } else {
             $urlConfig['width'] = $width;
             $urlConfig['height'] = $height;
         }
         // Create the responsive <amp-img /> tag
         $ampImg = $element->createWritableElement('amp-img');
         $ampImg->setAttribute('src', cloudinary_url($src, $urlConfig));
         $ampImg->setAttribute('width', $width);
         $ampImg->setAttribute('height', $height);
         $ampImg->setAttribute('sizes', $sizes);
         $ampImg->setAttribute('srcset', $srcset);
         $ampImg->setAttribute('layout', 'responsive');
         $ampImg->setAttribute('alt', $element->getAttribute('alt'));
         $ampImg->setAttribute('attribution', $element->getAttribute('attribution'));
         $ampImg->setAttribute('class', 'amp-img');
         $element->replaceWith($ampImg);
         $event->stopPropagation();
     }
 }
 public function handleTagImg(EventInterface $event, ElementInterface $element)
 {
     /** @var ElementInterface $ampImg */
     $ampImg = $element->createWritableElement('amp-img');
     foreach ($this->validAttributes as $attribute) {
         if ($element->getAttribute($attribute)) {
             $ampImg->setAttribute($attribute, $element->getAttribute($attribute));
         }
     }
     return $element->replaceWith($ampImg);
 }
 function it_skips_converting_non_youtube_object_tags(EventInterface $event, ElementInterface $element, ElementInterface $childElement)
 {
     $element->getChildren()->shouldBeCalled()->willReturn([$childElement]);
     $childElement->getAttribute('value')->shouldBeCalled()->willReturn('http://metube.com/embed/XGSy3_Czz8k');
     $event->stopPropagation()->shouldNotBeCalled();
     $element->createWritableElement('div', ['class' => 'youtube-container'])->shouldNotBeCalled();
     $this->handleObject($event, $element);
 }
 public function convertToAmp(ElementInterface $element)
 {
     if ($element->hasChildren() == false) {
         return false;
     }
     $hasClass = in_array('instagram-media', explode(' ', $element->getAttribute('class')));
     $hasAttr = array_key_exists('data-instgrm-version', $element->getAttributes());
     return $hasClass || $hasAttr;
 }
 /**
  * @param EventInterface $event
  * @param ElementInterface $element
  * @param $tag
  */
 public function handleBlockquote(EventInterface $event, ElementInterface $element, $tag)
 {
     $classAttr = explode(' ', $element->getAttribute('class'));
     if (in_array('twitter-tweet', $classAttr) && false !== ($twitterStatusId = $this->getStatusId($element))) {
         $container = $element->createWritableElement('div', ['class' => 'amp-twitter-container']);
         $container->appendChild($this->createAmpTwitterTag($element, $twitterStatusId));
         $element->replaceWith($container);
         $event->stopPropagation();
     }
 }
 public function handleIframe(EventInterface $event, ElementInterface $element)
 {
     $src = $element->getAttribute('src');
     if (1 === preg_match('/youtube\\.com\\/(?:v|embed)\\/([a-zA-z0-9_-]+)/i', $src, $match)) {
         $container = $element->createWritableElement('div', ['class' => 'youtube-container']);
         $container->appendChild($this->createAmpTag($element, $match[1]));
         $element->replaceWith($container);
         $event->stopPropagation();
     }
 }
 public function it_finds_the_instagram_code(ElementInterface $element)
 {
     $prophet = new Prophet();
     $anchor = $prophet->prophesize('Predmond\\HtmlToAmp\\Element');
     $anchor->getAttribute('href')->willReturn('https://www.instagram.com/p/AAA-aaa/');
     $sibling = $prophet->prophesize('Predmond\\HtmlToAmp\\Element');
     $sibling->getAttribute('href')->willReturn('');
     $parent = $prophet->prophesize('Predmond\\HtmlToAmp\\Element');
     $parent->getAttribute('href')->willReturn('');
     $parent->getChildren()->willReturn([$anchor, $sibling]);
     $element->getAttribute('href')->willReturn('');
     $element->getChildren()->willReturn([$parent]);
     $this->getEmbedShortcode($element)->shouldBe('AAA-aaa');
 }
 public function it_converts_an_image_to_amp_img(ElementInterface $ampImg, EventInterface $event, ElementInterface $element)
 {
     $ampImg->setAttribute('src', 'foo.jpg')->shouldBeCalled();
     $ampImg->setAttribute('width', 300)->shouldBeCalled();
     $ampImg->setAttribute('height', 250)->shouldBeCalled();
     $ampImg->setAttribute('class', 'amp-img')->shouldBeCalled();
     $ampImg->setAttribute('srcset', '')->shouldNotBeCalled();
     $ampImg->setAttribute('alt', '')->shouldNotBeCalled();
     $ampImg->setAttribute('attribution', '')->shouldNotBeCalled();
     $element->getAttribute('src')->shouldBeCalled()->willReturn('foo.jpg');
     $element->getAttribute('width')->shouldBeCalled()->willReturn(300);
     $element->getAttribute('height')->shouldBeCalled()->willReturn(250);
     $element->getAttribute('class')->shouldBeCalled()->willReturn('amp-img');
     $element->getAttribute('srcset')->shouldBeCalled()->willReturn('');
     $element->getAttribute('alt')->shouldBeCalled()->willReturn('');
     $element->getAttribute('attribution')->shouldBeCalled()->willReturn('');
     $element->createWritableElement('amp-img')->willReturn($ampImg);
     $element->replaceWith($ampImg)->shouldBeCalled();
     $this->handleTagImg($event, $element);
 }