Commit 4507edd13bb02cf45e46deced0c6bcc57ce67c71

Thomas de Grivel 2024-07-18T16:35:07

ekc3: support raw blocks

diff --git a/ekc3/ekc3.c b/ekc3/ekc3.c
index 72a7f41..639afe2 100644
--- a/ekc3/ekc3.c
+++ b/ekc3/ekc3.c
@@ -374,6 +374,31 @@ p_ekc3 * ekc3_init (p_ekc3 *ekc3)
   return ekc3;
 }
 
+s_str * ekc3_inspect_block (const s_block *block, s_str *dest)
+{
+  uw i = 0;
+  s_tag result = {0};
+  assert(block);
+  while (i < block->count) {
+    tag_clean(&result);
+    if (! eval_tag(block->tag + i, &result))
+      return NULL;
+    i++;
+  }
+  switch (result.type) {
+  case TAG_STR:
+    if (! str_init_copy(dest, &result.data.str))
+      return NULL;
+    break;
+  default:
+    if (! str_init_cast(dest, &g_sym_Str, &result))
+      return NULL;
+    break;
+  }
+  tag_clean(&result);
+  return dest;
+}
+
 sw ekc3_render (const p_ekc3 *ekc3)
 {
   const s_list *l;
@@ -407,54 +432,6 @@ sw ekc3_render (const p_ekc3 *ekc3)
   return result;
 }
 
-sw ekc3_render_block (const s_block *block)
-{
-  uw i = 0;
-  sw r;
-  s_tag result = {0};
-  assert(block);
-  while (i < block->count) {
-    tag_clean(&result);
-    if (! eval_tag(block->tag + i, &result))
-      return -1;
-    i++;
-  }
-  switch (result.type) {
-  case TAG_STR:
-    r = io_write_str(&result.data.str);
-    break;
-  default:
-    r = io_inspect_tag(&result);
-  }
-  tag_clean(&result);
-  return r;
-}
-
-s_str * ekc3_inspect_block (const s_block *block, s_str *dest)
-{
-  uw i = 0;
-  s_tag result = {0};
-  assert(block);
-  while (i < block->count) {
-    tag_clean(&result);
-    if (! eval_tag(block->tag + i, &result))
-      return NULL;
-    i++;
-  }
-  switch (result.type) {
-  case TAG_STR:
-    if (! str_init_copy(dest, &result.data.str))
-      return NULL;
-    break;
-  default:
-    if (! str_init_cast(dest, &g_sym_Str, &result))
-      return NULL;
-    break;
-  }
-  tag_clean(&result);
-  return dest;
-}
-
 sw ekc3_render_buf (s_buf *in)
 {
   p_ekc3 ekc3;
@@ -504,13 +481,48 @@ sw ekc3_render_file (const s_str *path)
   return r;
 }
 
+sw ekc3_render_raw_block (const s_block *block)
+{
+  uw i;
+  sw r;
+  s_tag result = {0};
+  assert(block);
+  i = 1;
+  while (i < block->count) {
+    tag_clean(&result);
+    if (! eval_tag(block->tag + i, &result))
+      return -1;
+    i++;
+  }
+  switch (result.type) {
+  case TAG_STR:
+    r = io_write_str(&result.data.str);
+    break;
+  default:
+    r = io_inspect_tag(&result);
+  }
+  tag_clean(&result);
+  return r;
+}
+
 sw ekc3_render_tag (const s_tag *tag)
 {
+  const s_block *block;
   s_str escaped = {0};
   s_str in = {0};
   sw r;
   switch(tag->type) {
   case TAG_BLOCK:
+    block = &tag->data.block;
+    if (block->count > 1 &&
+        block->tag->type == TAG_IDENT &&
+        block->tag->data.ident.sym == sym_1("raw")) {
+      if ((r = ekc3_render_raw_block(block)) < 0) {
+        err_puts("ekc3_render_tag: ekc3_render_raw_block");
+        assert(! "ekc3_render_tag: ekc3_render_raw_block");
+      }
+      return r;
+    }
     if (! ekc3_inspect_block(&tag->data.block, &in)) {
       err_puts("ekc3_render_tag: ekc3_render_block_to_str");
       assert(! "ekc3_render_tag: ekc3_render_block_to_str");
@@ -545,12 +557,3 @@ sw ekc3_render_tag (const s_tag *tag)
   err_write_1("\n");
   return -1;
 }
-
-s_fn * ekc3_to_render_fn (const p_ekc3 *ekc3, s_fn *dest)
-{
-  assert(ekc3);
-  assert(dest);
-  (void) ekc3;
-  (void) dest;
-  return NULL;
-}
diff --git a/test/ekc3/title.html.ekc3 b/test/ekc3/title.html.ekc3
index 7a86e6e..7175a13 100644
--- a/test/ekc3/title.html.ekc3
+++ b/test/ekc3/title.html.ekc3
@@ -6,6 +6,6 @@
     <% title2 = title + " H1 (silent block)" %>
     <h1><%= title2 %></h1>
     <h1><%= title_h1 %></h1>
-    <%= title_h2 %>
+    <%= raw title_h2 %>
   </body>
 </html>