return '';
}
+ if (isset($array['#comment'])) {
+ if (strpos($array['#comment'], '-->')) {
+ Civi::log()->warning('Afform: Cannot store comment with text "-->". Munging.');
+ $array['#comment'] = str_replace('-->', '-- >', $array['#comment']);
+ }
+ return sprintf('<!--%s-->', $array['#comment']);
+ }
+
$tag = empty($array['#tag']) ? self::DEFAULT_TAG : $array['#tag'];
unset($array['#tag']);
$children = empty($array['#children']) ? [] : $array['#children'];
return $node->textContent;
}
elseif ($node instanceof DOMComment) {
- // FIXME: How to preserve comments? For the moment, discarding them.
+ $arr = ['#comment' => $node->nodeValue];
+ return $arr;
}
else {
throw new \RuntimeException("Unrecognized DOM node");
public function getFormatExamples() {
$es = [];
- foreach (['empty', 'string', 'apple', 'banana', 'cherry'] as $exampleName) {
+ foreach (['empty', 'string', 'comments', 'apple', 'banana', 'cherry'] as $exampleName) {
$exampleFile = '/formatExamples/' . $exampleName . '.php';
$example = require __DIR__ . $exampleFile;
$formats = ['html', 'shallow', 'deep'];
--- /dev/null
+<?php
+
+return [
+ 'html' => '<div>One<!-- uno --> Two <!--dos & so on --> Three</div><!--tres-a--b---c-->',
+ 'shallow' => [
+ [
+ '#tag' => 'div',
+ '#children' => [
+ 'One',
+ ['#comment' => ' uno '],
+ ' Two ',
+ ['#comment' => 'dos & so on '],
+ ' Three',
+ ],
+ ],
+ ['#comment' => 'tres-a--b---c'],
+ ],
+ 'deep' => [
+ [
+ '#tag' => 'div',
+ '#children' => [
+ 'One',
+ ['#comment' => ' uno '],
+ ' Two ',
+ ['#comment' => 'dos & so on '],
+ ' Three',
+ ],
+ ],
+ ['#comment' => 'tres-a--b---c'],
+ ],
+];