From 8b8761cd7d90e03dcf6556a9c8cd7a68ad313c03 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 5 Nov 2014 15:37:37 -0800 Subject: Added basic infrastructure for render_stack. --- src/html/html.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/html') 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) -- cgit v1.2.3