edit/page: indicate edit replacements in data-dyn attributes
[minimedit.git] / page.php
index ed0ec1b9af93772e0b9cbbbc15e1721846ad9ffe..75540b64d06c9ebcd84f1a744f8083989a2028d0 100644 (file)
--- a/page.php
+++ b/page.php
@@ -58,19 +58,17 @@ function getoutput($blocks = [])
        $doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?</\1>}s', '', $doc);
 
        return preg_replace_callback(
-               '{ (?<! <!--BLOCK: ) \[\[ ([^] ]+) ([^]]*) \]\] }x',
+               '{ \[\[ ([^] ]+) ([^]]*) \]\] }x',
                function ($sub) use ($blocks) {
                        list ($placeholder, $name, $params) = $sub;
-                       if (isset($blocks[$name])) {
-                               $html = $blocks[$name];
+                       $html = $blocks[$name] ??
+                               placeholder_include($name, explode(' ', $params));
+                       if (empty($html) or $html[0] != '<') {
+                               $html = "<span>$html</span>";
                        }
-                       else {
-                               $html = placeholder_include($name, explode(' ', $params));
-                       }
-                       return sprintf('<!--BLOCK:%s-->%s<!--/-->',
-                               is_numeric($name) ? '' : $placeholder, # edit replacement
-                               preg_replace('{<!--[^-]*-->}', '', $html) # contents
-                       );
+                       $attr = sprintf(' data-dyn="%s"', is_numeric($name) ? '' : $name.$params);
+                       # contents with identifier in first tag
+                       return preg_replace( '/(?=>)/', $attr, $html, 1);
                },
                $doc
        );