summaryrefslogtreecommitdiff
path: root/src/html
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-05 15:37:37 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-05 15:37:37 -0800
commit8b8761cd7d90e03dcf6556a9c8cd7a68ad313c03 (patch)
treeee84d73ce0fc07e6ddb7fc94b15980789e879aee /src/html
parent3b8023db4fb2f11ee9c0f61a3d92ab5c40aaad6d (diff)
Added basic infrastructure for render_stack.
Diffstat (limited to 'src/html')
-rw-r--r--src/html/html.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/html/html.c b/src/html/html.c
index fde1cb4..6d60149 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -8,6 +8,63 @@
#include "debug.h"
#include "html/houdini.h"
+typedef struct RenderStack {
+ struct RenderStack *previous;
+ chunk literal;
+ union {
+ node_inl *inl;
+ node_block *block;
+ } next_sibling;
+ bool tight;
+} render_stack;
+
+static void free_render_stack(render_stack * stack)
+{
+ render_stack * tempstack;
+ while (stack) {
+ tempstack = stack;
+ stack = stack->previous;
+ chunk_free(&tempstack->literal);
+ free(tempstack);
+ }
+}
+
+static render_stack* push_inline(render_stack* stack,
+ node_inl* inl,
+ char* literal)
+{
+ render_stack* newstack;
+ newstack = (render_stack*)malloc(sizeof(render_stack));
+ newstack->previous = stack;
+ newstack->next_sibling.inl = inl;
+ newstack->literal = chunk_literal(literal);
+ return newstack;
+}
+
+static render_stack* push_block(render_stack* stack,
+ node_block* block,
+ char* literal,
+ bool tight)
+{
+ render_stack* newstack;
+ newstack = (render_stack*)malloc(sizeof(render_stack));
+ newstack->previous = stack;
+ newstack->next_sibling.block = block;
+ newstack->literal = chunk_literal(literal);
+ newstack->tight = tight;
+ return newstack;
+}
+
+static render_stack* pop_render_stack(render_stack* stack)
+{
+ render_stack* top = stack;
+ if (stack == NULL) {
+ return NULL;
+ }
+ stack = stack->previous;
+ return top;
+}
+
// Functions to convert node_block and inline lists to HTML strings.
static void escape_html(strbuf *dest, const unsigned char *source, int length)