Add html to custom element Sanitizer and custom element to html normalizer
Open
requested to merge issue/custom_elements-3494426:3494426-create-html-to-CE-converter-and-ce-to-html-normalizer into 3.x
3 unresolved threads
Closes #3494426
Merge request reports
Activity
- Resolved by Mustapha Ben Ellafi
- Resolved by Mustapha Ben Ellafi
- Resolved by Mustapha Ben Ellafi
- Resolved by Mustapha Ben Ellafi
- Resolved by Mustapha Ben Ellafi
- Resolved by Mustapha Ben Ellafi
- src/HtmlParser.php 0 → 100644
25 */ 26 public function __construct() { 27 $this->html5Parser = new HTML5(); 28 } 29 30 /** 31 * Converts HTML content to a CustomElement tree structure. 32 * 33 * @param string $htmlContent 34 * The HTML content to convert. 35 * 36 * @return \Drupal\custom_elements\CustomElement|null 37 * Returns the root CustomElement or NULL if conversion fails. 38 */ 39 public function convertHtmlToCustomElement(string $htmlContent): ?CustomElement { 40 $dom = $this->html5Parser->loadHTML($htmlContent); instead of using the html5parsers directly, I think we shall use https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Utility%21Html.php/function/Html%3A%3Aload/10
so we keep using whatever library Drupal uses internally + avoid introducing a new dependency (which we would have to declare else)
7 7 use Symfony\Component\Serializer\Normalizer\NormalizerInterface; 8 8 9 9 /** 10 * Formats a custom element structure into an array. 10 * Formats a custom element structure into an array or HTML string. I don't see why we are changing/extending the purpose of this class. Rendering custom_elements to html markup works via the drupal render system and I don't see why this issue requires us to change it.
We can and maybe should mention this in the class docblock comment here though + clearly document which "format" is supported
- tests/src/Kernel/HtmlParserTest.php 0 → 100644
30 */ 31 protected static $modules = ['custom_elements']; 32 33 /** 34 * {@inheritdoc} 35 */ 36 protected function setUp(): void { 37 parent::setUp(); 38 $this->htmlParser = $this->container->get('custom_elements.html_parser'); 39 $this->normalizer = $this->container->get('custom_elements.normalizer'); 40 } 41 42 /** 43 * Tests converting HTML content to custom elements and back. 44 */ 45 public function testHtmlToCustomElementAndBack() {
Please register or sign in to reply