From d3ed59c2753c2babd5aa9a1c5e0109c644904ba8 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 21 Nov 2019 01:20:31 +0100 Subject: [PATCH] edit/page: indicate edit replacements in data-dyn attributes 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 | 5 +++-- page.php | 18 ++++++++---------- widget/nieuws.php | 4 ++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/edit/page.js b/edit/page.js index 9997e29..3071844 100644 --- a/edit/page.js +++ b/edit/page.js @@ -161,8 +161,9 @@ if (pagebody) { editlink.href = ''; editlink.onclick = undefined; pagebody.setAttribute('contenteditable', true); - pagebody.innerHTML = pagebody.innerHTML - .replace(/[^]*?/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; diff --git a/page.php b/page.php index ed0ec1b..75540b6 100644 --- a/page.php +++ b/page.php @@ -58,19 +58,17 @@ function getoutput($blocks = []) $doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?}s', '', $doc); return preg_replace_callback( - '{ (?$html"; } - else { - $html = placeholder_include($name, explode(' ', $params)); - } - return sprintf('%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 ); diff --git a/widget/nieuws.php b/widget/nieuws.php index 0dc8d7d..c1b651a 100644 --- a/widget/nieuws.php +++ b/widget/nieuws.php @@ -3,6 +3,7 @@ if (!function_exists('shownews')) { function shownews($input, $limit = 1000) { if (!is_array($input)) $input = glob("$input/*.html"); + print "
\n"; foreach (array_reverse($input) as $filename) { $article = new ArchiveArticle($filename); print '
'; @@ -24,6 +25,7 @@ function shownews($input, $limit = 1000) if (--$limit <= 0) break; } + print "
\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 "
\n"; foreach (array_reverse(glob("$articles/2???")) as $page) { $year = basename($page, '.html'); printf('

%s

'."\n", $page, $year); printtoc($page, 'gallery'); } + print "
\n"; return; } $articles .= '/????'; -- 2.30.0