edit/page: indicate edit replacements in data-dyn attributes
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 21 Nov 2019 00:20:31 +0000 (01:20 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 5 Dec 2020 00:41:05 +0000 (01:41 +0100)
Clean up hack of html comments by a proper dom integration.
Does require placeholders to be wrapped in a single outer element.

edit/page.js
page.php
widget/nieuws.php

index 9997e293c7615a3af4c6b29945f56583503a49e5..3071844a96e685c64d8ae6328e81af773e940bc2 100644 (file)
@@ -161,8 +161,9 @@ if (pagebody) {
                editlink.href = '';
                editlink.onclick = undefined;
                pagebody.setAttribute('contenteditable', true);
-               pagebody.innerHTML = pagebody.innerHTML
-                       .replace(/<!--BLOCK:(.*?)-->[^]*?<!--\/-->/g, '$1');
+               pagebody.querySelectorAll('[data-dyn]').forEach(function (el) {
+                       el.outerHTML = '[[' + el.getAttribute('data-dyn') + ']]';
+               });
                CKEDITOR.inline(pagebody, { customConfig: '' });
                document.body.className = 'edit';
                return false;
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
        );
index 0dc8d7dcc56c52062f70ba40bb7de67748c3f8da..c1b651a44853bd5ddb49c5383b7d0fb3bb4e4ab9 100644 (file)
@@ -3,6 +3,7 @@ if (!function_exists('shownews')) {
 function shownews($input, $limit = 1000)
 {
        if (!is_array($input)) $input = glob("$input/*.html");
+       print "<div>\n";
        foreach (array_reverse($input) as $filename) {
                $article = new ArchiveArticle($filename);
                print '<article class="left">';
@@ -24,6 +25,7 @@ function shownews($input, $limit = 1000)
 
                if (--$limit <= 0) break;
        }
+       print "</div>\n";
 }
 
 function printtoc($input, $class = FALSE)
@@ -54,11 +56,13 @@ function printtoc($input, $class = FALSE)
 $articles = (ltrim($Args, '/') ?: 'nieuws');
 if (strpos($articles, '/') === FALSE) {
        if (@$Place['view'] === 'toc') {
+               print "<div>\n";
                foreach (array_reverse(glob("$articles/2???")) as $page) {
                        $year = basename($page, '.html');
                        printf('<h3><a href="/%s">%s</a></h3>'."\n", $page, $year);
                        printtoc($page, 'gallery');
                }
+               print "</div>\n";
                return;
        }
        $articles .= '/????';