/**
  * {@inheritdoc}
  */
 public function render(Converter $converter = null)
 {
     $json = ['name' => Converter::carbonId(), 'component' => 'HTMLComponent', 'html' => html_entity_decode($this->element->getValue())];
     // if ($provider['sizes']) {
     //     $json['sizes'] = $provider['sizes'];
     // }
     return $json;
 }
 public function testConvertsHtmlToJson()
 {
     $converter = new Converter();
     // add custom attributes to formatting component
     // $paragraph = new Paragraph([
     //     'a' => function ($attrs, $text) {
     //         return [
     //             'rel' => 'nofollow'
     //         ];
     //     }
     // ]);
     // $converter->addComponent('Paragraph', $paragraph);
     $input = "\n            <div>\n                <div>\n                    <p>Yes, <strong>The Crystal Maze</strong>, 90s game show staple and <em>stunning example</em> of the kind of weird British TV that's hard to explain to Americans, has returned. It's now a live theatre meets escape the room meets team building meets frantically <a href=\"http://www.google.com\">running</a> and shouting experience that plays out wonderfully, almost terrifyingly, exactly the same as when you watched it on TV.</p>\n                    <p>For anyone that was too young when it was actually airing, or never caught any of the repeats, a brief summary: in The Crystal Maze a team of people in stunning jumpsuits would rush around four differently themed zones to complete timed puzzles in little rooms (puzzles being either Physical, Mental, or Skill based, with Mystery as a wild card) and thus earn crystals. Every crystal earned gave the team five seconds in the Crystal Dome, where they had to catch gold tickets that were blown around the dome with fans. If they managed to get enough of said tickets then they earned a distinctly underwhelming prize, like a weekend spent pro–sandcastling in Torbay. They were shepherded around the whole thing by Richard O'Brien, clothed in leopard print and visible distain, who alternated making weird commentary with playing the harmonica.</p>\n                    <h3>Something in the water</h3>\n                    <p>The Crystal Maze has not made the transition from TV show to live show in its original form: it now lives in a subdued, white fronted building off Islington High Street, which doesn't even say 'The Crystal Maze' yet – the building number is stuck on the door on an A4 sheet of paper, and looks like the kind of place you'd go to to meet a guy named Hillary who'd offered to sell you a load of printers wholesale. The inside is more what you'd expect, with a crowd of people in different coloured bomber jackets colliding with other, more sweaty people, who're humming the theme tune and collecting their coats from lockers. Our team was duly lead into a stone walled room to be introduced to our Maze Master.</p>\n                    <p><em>The Maze Masters</em> are probably the most significant change to the game. Richard O'Brien is now north of 70, and can't run four teams simultaneously. Instead, each team has their own Maze Master to keep the energy high, and they all take the time to learn your names and create a unique experience. They're also all equipped with radios and mics to receive instructions and time check with \"Mumsie\" if necessary, so it all runs incredibly smoothly despite four teams of eight people cycling around the maze.</p>\n                    <p>embed://videogamer.com/media/crystal-maze-aztec</p>\n                    <p>Our Maze Master was most easily compared to Peter Davison's Doctor Who if he'd been more engaging, and introduced himself with a complex hyphenated name that boiled down to the initials TBC (\"But you can call me T**s for short!\"). The other teams in our session had a high energy woman who looked like she was about to lead an 80s jazzercise class, a man in a loose harlequin onesie who hid all the crystals in his hat and kept signalling his team to screech like eagles, and a louche 19th century piratical type – the kind that probably has some kind of infection, but is too busy chartering a ship to fight in the Greek War of Independence to care.</p>\n                    <p>These, then, are just some of the characters that could be sprinting you around the maze (and sprint you will) to tackle the different games therein. There's a mix of puzzles from the original show as well as entirely new ones, with their difficulty ricocheting wildly between easy and impossibly hard. I witnessed my friend almost doing the splits across a rope obstacle course, and a woman I didn't know Zeta–Jonesing it through a web of lasers like a pro, whilst another of our number fell off a rotating log and was locked in. Trapped players on the TV show would either have to be rescued at the expense of a crystal or just forfeit the rest of the game, but for the live show they'll be able to earn their way out by completing a puzzle, or you automatically burn a crystal to get them back – which  makes sense, since for a weekend ticket your time in the maze is costing you just under a quid a minute. Our team member was clever enough to get himself out of the Aztec Zone by himself.</p>\n                    <p>The Zones themselves are beautifully realised, even if you'd never seen the show. The Aztec Zone is oppressively hot and gets sand in your shoes, and the Medieval Zone is incredibly cold and decorated with cobwebs and candelabra. You also get a tour of the Industrial and Futuristic Zones (Ocean Zone, it was explained, does not feature, because that amount of standing water is impossible to insure). The puzzles are loosely themed to the Zone you're in, so in the Futuristic Zone we had to navigate a player through an invisible maze, and put together a stained glass window in the Medieval. And the weird thing is that you do everything they do on TV.</p>\n                    <p>embed://videogamer.com/media/crystal-maze-dome</p>\n                    <p>You yell \"Come out, come out!\" at players close to their time limit, but \"Plenty of time!\" when they still have 30 seconds. Shouting nonsensical instructions: \"Go left! No, right, sorry. Go back go back go back!\", in situations that would have you yelling at your TV screen at home. I was made team captain, and said stuff like \"Okay, let's have a... Physical challenge! For… James!\" with the exact cadence and tone of voice that every other team captain has ever had. It's as if The Crystal Maze has an eldritch power over anyone who enters, and you suddenly understand anyone else who played it, linked across time and space through a vortex centred around the Crystal Dome itself.</p>\n                    <p>The Dome. A brightly lit, crystalline prison. There is surely nothing on earth like hearing \"Will you start the fans, please!\", feeling the rush of air, and losing all sense of focus, of planned tactics, as the music kicks in and your vision is clouded by a blizzard of shiny paper. It's joyous, kind of a bit naff, but inexplicably perfect.</p>\n                    <p>We came last. We were, frankly, robbed. So I'm going to go again.</p>\n                    <p><em>Full disclosure: I funded The Crystal Maze Live by buying a ticket from its Kickstarter, which, functionally, means that I'm one of the only journalists doing a write up of it that actually had to pay for a ticket. I have also technically been \"friends\" with Dean Rodgers, the Creative Director of the project, for the past couple of years, but this shouldn't be read to mean that I like him very much. He's insufferable.</em>\n                    </p>\n                </div>\n                <div>\n                    <p>Element one</p>\n                    <p>Element two</p>\n                </div>\n            </div>\n            <div>\n                <div>\n                    <p>Element three</p>\n                    <p>Element four</p>\n                </div>\n                <div>\n                    <div>\n                        <p>Element five</p>\n                        <p>Element six</p>\n                        <p><img src=\"picture.jpg\"></p>\n                    </div>\n                </div>\n            </div>";
     $expected = '[{"name":"e24a04f2","component":"Section","components":[{"name":"d4f92a6d","component":"Layout","tagName":"div","type":"layout-single-column","components":[{"name":"36cf5582","component":"Paragraph","text":"Yes, The Crystal Maze, 90s game show staple and stunning example of the kind of weird British TV that\'s hard to explain to Americans, has returned. It\'s now a live theatre meets escape the room meets team building meets frantically running and shouting experience that plays out wonderfully, almost terrifyingly, exactly the same as when you watched it on TV.","placeholderText":null,"paragraphType":"p","formats":[{"type":"strong","from":5,"to":21},{"type":"em","from":48,"to":64},{"type":"a","from":232,"to":239,"attrs":{"href":"http:\\/\\/www.google.com"}}]},{"name":"c1f261f2","component":"Paragraph","text":"For anyone that was too young when it was actually airing, or never caught any of the repeats, a brief summary: in The Crystal Maze a team of people in stunning jumpsuits would rush around four differently themed zones to complete timed puzzles in little rooms (puzzles being either Physical, Mental, or Skill based, with Mystery as a wild card) and thus earn crystals. Every crystal earned gave the team five seconds in the Crystal Dome, where they had to catch gold tickets that were blown around the dome with fans. If they managed to get enough of said tickets then they earned a distinctly underwhelming prize, like a weekend spent pro\\u2013sandcastling in Torbay. They were shepherded around the whole thing by Richard O\'Brien, clothed in leopard print and visible distain, who alternated making weird commentary with playing the harmonica.","placeholderText":null,"paragraphType":"p"},{"name":"f2178860","component":"Paragraph","text":"Something in the water","placeholderText":null,"paragraphType":"h3"},{"name":"59c65898","component":"Paragraph","text":"The Crystal Maze has not made the transition from TV show to live show in its original form: it now lives in a subdued, white fronted building off Islington High Street, which doesn\'t even say \'The Crystal Maze\' yet \\u2013 the building number is stuck on the door on an A4 sheet of paper, and looks like the kind of place you\'d go to to meet a guy named Hillary who\'d offered to sell you a load of printers wholesale. The inside is more what you\'d expect, with a crowd of people in different coloured bomber jackets colliding with other, more sweaty people, who\'re humming the theme tune and collecting their coats from lockers. Our team was duly lead into a stone walled room to be introduced to our Maze Master.","placeholderText":null,"paragraphType":"p"},{"name":"045259d4","component":"Paragraph","text":"The Maze Masters are probably the most significant change to the game. Richard O\'Brien is now north of 70, and can\'t run four teams simultaneously. Instead, each team has their own Maze Master to keep the energy high, and they all take the time to learn your names and create a unique experience. They\'re also all equipped with radios and mics to receive instructions and time check with \\"Mumsie\\" if necessary, so it all runs incredibly smoothly despite four teams of eight people cycling around the maze.","placeholderText":null,"paragraphType":"p","formats":[{"type":"em","from":0,"to":16}]},{"name":"c25ee8f4","component":"Paragraph","text":"embed:\\/\\/videogamer.com\\/media\\/crystal-maze-aztec","placeholderText":null,"paragraphType":"p"},{"name":"351cc773","component":"Paragraph","text":"Our Maze Master was most easily compared to Peter Davison\'s Doctor Who if he\'d been more engaging, and introduced himself with a complex hyphenated name that boiled down to the initials TBC (\\"But you can call me T**s for short!\\"). The other teams in our session had a high energy woman who looked like she was about to lead an 80s jazzercise class, a man in a loose harlequin onesie who hid all the crystals in his hat and kept signalling his team to screech like eagles, and a louche 19th century piratical type \\u2013 the kind that probably has some kind of infection, but is too busy chartering a ship to fight in the Greek War of Independence to care.","placeholderText":null,"paragraphType":"p"},{"name":"1cab4580","component":"Paragraph","text":"These, then, are just some of the characters that could be sprinting you around the maze (and sprint you will) to tackle the different games therein. There\'s a mix of puzzles from the original show as well as entirely new ones, with their difficulty ricocheting wildly between easy and impossibly hard. I witnessed my friend almost doing the splits across a rope obstacle course, and a woman I didn\'t know Zeta\\u2013Jonesing it through a web of lasers like a pro, whilst another of our number fell off a rotating log and was locked in. Trapped players on the TV show would either have to be rescued at the expense of a crystal or just forfeit the rest of the game, but for the live show they\'ll be able to earn their way out by completing a puzzle, or you automatically burn a crystal to get them back \\u2013 which makes sense, since for a weekend ticket your time in the maze is costing you just under a quid a minute. Our team member was clever enough to get himself out of the Aztec Zone by himself.","placeholderText":null,"paragraphType":"p"},{"name":"0c41f828","component":"Paragraph","text":"The Zones themselves are beautifully realised, even if you\'d never seen the show. The Aztec Zone is oppressively hot and gets sand in your shoes, and the Medieval Zone is incredibly cold and decorated with cobwebs and candelabra. You also get a tour of the Industrial and Futuristic Zones (Ocean Zone, it was explained, does not feature, because that amount of standing water is impossible to insure). The puzzles are loosely themed to the Zone you\'re in, so in the Futuristic Zone we had to navigate a player through an invisible maze, and put together a stained glass window in the Medieval. And the weird thing is that you do everything they do on TV.","placeholderText":null,"paragraphType":"p"},{"name":"ef1c359c","component":"Paragraph","text":"embed:\\/\\/videogamer.com\\/media\\/crystal-maze-dome","placeholderText":null,"paragraphType":"p"},{"name":"2c9574c2","component":"Paragraph","text":"You yell \\"Come out, come out!\\" at players close to their time limit, but \\"Plenty of time!\\" when they still have 30 seconds. Shouting nonsensical instructions: \\"Go left! No, right, sorry. Go back go back go back!\\", in situations that would have you yelling at your TV screen at home. I was made team captain, and said stuff like \\"Okay, let\'s have a... Physical challenge! For\\u2026 James!\\" with the exact cadence and tone of voice that every other team captain has ever had. It\'s as if The Crystal Maze has an eldritch power over anyone who enters, and you suddenly understand anyone else who played it, linked across time and space through a vortex centred around the Crystal Dome itself.","placeholderText":null,"paragraphType":"p"},{"name":"20f99efb","component":"Paragraph","text":"The Dome. A brightly lit, crystalline prison. There is surely nothing on earth like hearing \\"Will you start the fans, please!\\", feeling the rush of air, and losing all sense of focus, of planned tactics, as the music kicks in and your vision is clouded by a blizzard of shiny paper. It\'s joyous, kind of a bit naff, but inexplicably perfect.","placeholderText":null,"paragraphType":"p"},{"name":"2380c716","component":"Paragraph","text":"We came last. We were, frankly, robbed. So I\'m going to go again.","placeholderText":null,"paragraphType":"p"},{"name":"c4078d53","component":"Paragraph","text":"Full disclosure: I funded The Crystal Maze Live by buying a ticket from its Kickstarter, which, functionally, means that I\'m one of the only journalists doing a write up of it that actually had to pay for a ticket. I have also technically been \\"friends\\" with Dean Rodgers, the Creative Director of the project, for the past couple of years, but this shouldn\'t be read to mean that I like him very much. He\'s insufferable.","placeholderText":null,"paragraphType":"p","formats":[{"type":"em","from":0,"to":421}]}]}]},{"name":"eaf7e809","component":"Section","components":[{"name":"f010ec70","component":"Layout","tagName":"div","type":"layout-single-column","components":[{"name":"db5632b0","component":"Paragraph","text":"Element one","placeholderText":null,"paragraphType":"p"},{"name":"9d930a0e","component":"Paragraph","text":"Element two","placeholderText":null,"paragraphType":"p"}]}]},{"name":"37b3476c","component":"Section","components":[{"name":"d8c58712","component":"Layout","tagName":"div","type":"layout-single-column","components":[{"name":"36c8c49b","component":"Paragraph","text":"Element three","placeholderText":null,"paragraphType":"p"},{"name":"45be672c","component":"Paragraph","text":"Element four","placeholderText":null,"paragraphType":"p"}]}]},{"name":"74a11468","component":"Section","components":[{"name":"17029c2f","component":"Layout","tagName":"div","type":"layout-single-column","components":[{"name":"9c1dccd7","component":"Paragraph","text":"Element five","placeholderText":null,"paragraphType":"p"},{"name":"00d8c7c5","component":"Paragraph","text":"Element six","placeholderText":null,"paragraphType":"p"}]}]}]';
     $output = $converter->convert($input);
     // go through output/expected and remove randomised elements
     $expected = preg_replace("/\"name\"\\:\"(.*?)\"/i", "\"name\": \"12345678\"", $expected);
     $output = preg_replace("/\"name\"\\:\"(.*?)\"/i", "\"name\": \"12345678\"", $output);
     $this->assertSame($expected, $output);
 }
 /**
  * {@inheritdoc}
  */
 public function render(Converter $converter = null)
 {
     $provider = $this->config['providerCallback']($this->element->getValue());
     // caption text?
     $caption = !empty($this->element->getAttribute('data-caption')) ? $this->element->getAttribute('data-caption') : '';
     $json = ['name' => Converter::carbonId(), 'component' => 'EmbeddedComponent', 'url' => $this->element->getValue(), 'caption' => $caption, 'provider' => $provider['provider'], 'type' => $provider['type'], 'serviceName' => $provider['serviceName']];
     if ($provider['sizes']) {
         $json['sizes'] = $provider['sizes'];
     }
     return $json;
 }
 /**
  * Construct paragraph component
  *
  * @param  \Candybanana\HtmlToCarbonJson\Element|null
  * @return array
  */
 protected function makeParagraph(Element $element = null)
 {
     $element = $element ?: $this->element;
     $json = ['name' => Converter::carbonId(), 'component' => 'Paragraph', 'text' => $element->getValue(), 'placeholderText' => null, 'paragraphType' => $this->paragraphType($element)];
     if ($formats = $this->detectFormatting($element)) {
         $json['formats'] = $formats;
     }
     return $json;
 }
 /**
  * {@inheritdoc}
  */
 public function getLayout()
 {
     return ['name' => Converter::carbonId(), 'component' => 'Layout', 'tagName' => 'div', 'type' => $this->config['layoutTypeCallback']($this->element)];
 }