From e216094e2192c05ddbd0988458eb8c0012e7baf8 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 2 Sep 2014 01:10:54 +0200 Subject: lol --- src/stmd.h | 76 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 5e34399..eb1b989 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -1,38 +1,38 @@ #include -#include "bstrlib.h" +#include "buffer.h" #include "uthash.h" #define VERSION "0.1" #define CODE_INDENT 4 +typedef struct { + const unsigned char *data; + int len; + int alloc; +} chunk; + typedef struct Inline { - enum { str, softbreak, linebreak, code, raw_html, entity, - emph, strong, link, image } tag; - union { - bstring literal; - struct Inline* inlines; - struct { struct Inline* label; - bstring url; - bstring title; - } linkable; - } content; - struct Inline* next; + enum { str, softbreak, linebreak, code, raw_html, entity, + emph, strong, link, image } tag; + union { + chunk literal; + struct Inline *inlines; + struct { + struct Inline *label; + unsigned char *url; + unsigned char *title; + } linkable; + } content; + struct Inline *next; } inl; typedef struct Reference { - bstring label; - bstring url; - bstring title; + unsigned char *label; + unsigned char *url; + unsigned char *title; UT_hash_handle hh; // used by uthash } reference; -typedef struct Subject { - bstring buffer; - int pos; - reference** reference_map; - int label_nestlevel; -} subject; - // Types for blocks struct ListData { @@ -51,7 +51,7 @@ struct FencedCodeData { int fence_length; int fence_offset; char fence_char; - bstring info; + gh_buf info; }; typedef struct Block { @@ -77,7 +77,8 @@ typedef struct Block { struct Block* last_child; struct Block* parent; struct Block* top; - bstring string_content; + gh_buf string_content; + int string_pos; inl* inline_content; union { struct ListData list_data; @@ -89,33 +90,34 @@ typedef struct Block { struct Block * prev; } block; -int parse_inline(subject* subj, inl ** last); -inl* parse_inlines(bstring input, reference** refmap); -inl* parse_inlines_while(subject* subj, int (*f)(subject*)); +inl* parse_inlines(gh_buf *input, int input_pos, reference** refmap); void free_inlines(inl* e); -int parse_reference(bstring input, reference** refmap); + +int parse_reference(gh_buf *input, int input_pos, reference** refmap); void free_reference(reference *ref); void free_reference_map(reference **refmap); -reference* make_reference(bstring label, bstring url, bstring title); -reference* lookup_reference(reference** refmap, bstring label); + void add_reference(reference** refmap, reference* ref); -int unescape(bstring s); +void unescape_buffer(gh_buf *buf); extern block* make_document(); extern block* add_child(block* parent, int block_type, int start_line, int start_column); void free_blocks(block* e); +block *stmd_parse_document(const char *buffer, size_t len); + // FOR NOW: -int process_inlines(block* cur, reference** refmap); -int incorporate_line(bstring ln, int line_number, block** curptr); -int finalize(block* b, int line_number); +void process_inlines(block* cur, reference** refmap); +void incorporate_line(gh_buf *ln, int line_number, block** curptr); +void finalize(block* b, int line_number); void print_inlines(inl* ils, int indent); void print_blocks(block* blk, int indent); -int blocks_to_html(block* b, bstring* result, bool tight); -int inlines_to_html(inl* b, bstring* result); +/* TODO */ +// int blocks_to_html(block* b, bstring* result, bool tight); +// int inlines_to_html(inl* b, bstring* result); -int bdetab(bstring s, int utf8); +void utf8proc_case_fold(gh_buf *dest, const unsigned char *str, int len); -- cgit v1.2.3 From 582674e662d1f8757350c51486a5e0a837195e15 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 2 Sep 2014 13:18:04 +0200 Subject: ffffix --- src/stmd.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index eb1b989..dc24235 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -105,19 +105,14 @@ extern block* add_child(block* parent, int block_type, int start_line, int start_column); void free_blocks(block* e); -block *stmd_parse_document(const char *buffer, size_t len); - -// FOR NOW: -void process_inlines(block* cur, reference** refmap); -void incorporate_line(gh_buf *ln, int line_number, block** curptr); -void finalize(block* b, int line_number); +extern block *stmd_parse_document(const unsigned char *buffer, size_t len); +extern block *stmd_parse_file(FILE *f); void print_inlines(inl* ils, int indent); void print_blocks(block* blk, int indent); -/* TODO */ -// int blocks_to_html(block* b, bstring* result, bool tight); -// int inlines_to_html(inl* b, bstring* result); +void blocks_to_html(gh_buf *html, block *b, bool tight); +void inlines_to_html(gh_buf *html, inl *b); void utf8proc_case_fold(gh_buf *dest, const unsigned char *str, int len); -- cgit v1.2.3 From 24248c0f1a6de6f229890c5c03aeff8738214fee Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 2 Sep 2014 13:30:13 +0200 Subject: Rename inlines --- src/stmd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index dc24235..1e490d6 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -12,8 +12,8 @@ typedef struct { } chunk; typedef struct Inline { - enum { str, softbreak, linebreak, code, raw_html, entity, - emph, strong, link, image } tag; + enum { INL_STRING, INL_SOFTBREAK, INL_LINEBREAK, INL_CODE, INL_RAW_HTML, INL_ENTITY, + INL_EMPH, INL_STRONG, INL_LINK, INL_IMAGE } tag; union { chunk literal; struct Inline *inlines; -- cgit v1.2.3 From c28af79329264a7cf331a1b1c414919e4ed9e9f9 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 2 Sep 2014 13:37:34 +0200 Subject: It buiiiilds --- src/stmd.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 1e490d6..3e284bd 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -1,4 +1,5 @@ #include +#include #include "buffer.h" #include "uthash.h" -- cgit v1.2.3 From a7314deae649646f1f7ce5ede972641b5b62538c Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Wed, 3 Sep 2014 03:40:23 +0200 Subject: 338/103 --- src/stmd.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 3e284bd..4a3c399 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -1,17 +1,15 @@ +#ifndef _STDMD_H_ +#define _STDMD_H_ + #include #include #include "buffer.h" +#include "chunk.h" #include "uthash.h" #define VERSION "0.1" #define CODE_INDENT 4 -typedef struct { - const unsigned char *data; - int len; - int alloc; -} chunk; - typedef struct Inline { enum { INL_STRING, INL_SOFTBREAK, INL_LINEBREAK, INL_CODE, INL_RAW_HTML, INL_ENTITY, INL_EMPH, INL_STRONG, INL_LINK, INL_IMAGE } tag; @@ -79,7 +77,6 @@ typedef struct Block { struct Block* parent; struct Block* top; gh_buf string_content; - int string_pos; inl* inline_content; union { struct ListData list_data; @@ -91,10 +88,10 @@ typedef struct Block { struct Block * prev; } block; -inl* parse_inlines(gh_buf *input, int input_pos, reference** refmap); +inl* parse_inlines(gh_buf *input, reference** refmap); void free_inlines(inl* e); -int parse_reference(gh_buf *input, int input_pos, reference** refmap); +int parse_reference(gh_buf *input, reference** refmap); void free_reference(reference *ref); void free_reference_map(reference **refmap); @@ -117,3 +114,4 @@ void inlines_to_html(gh_buf *html, inl *b); void utf8proc_case_fold(gh_buf *dest, const unsigned char *str, int len); +#endif -- cgit v1.2.3 From 543c2c94d71adee42c7bd2f8027d75c87ed8120d Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 4 Sep 2014 18:38:14 +0200 Subject: Rename to strbuf --- src/stmd.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 4a3c399..2e86f3a 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -50,7 +50,7 @@ struct FencedCodeData { int fence_length; int fence_offset; char fence_char; - gh_buf info; + strbuf info; }; typedef struct Block { @@ -76,7 +76,7 @@ typedef struct Block { struct Block* last_child; struct Block* parent; struct Block* top; - gh_buf string_content; + strbuf string_content; inl* inline_content; union { struct ListData list_data; @@ -88,15 +88,15 @@ typedef struct Block { struct Block * prev; } block; -inl* parse_inlines(gh_buf *input, reference** refmap); +inl* parse_inlines(strbuf *input, reference** refmap); void free_inlines(inl* e); -int parse_reference(gh_buf *input, reference** refmap); +int parse_reference(strbuf *input, reference** refmap); void free_reference(reference *ref); void free_reference_map(reference **refmap); void add_reference(reference** refmap, reference* ref); -void unescape_buffer(gh_buf *buf); +void unescape_buffer(strbuf *buf); extern block* make_document(); extern block* add_child(block* parent, @@ -109,9 +109,9 @@ extern block *stmd_parse_file(FILE *f); void print_inlines(inl* ils, int indent); void print_blocks(block* blk, int indent); -void blocks_to_html(gh_buf *html, block *b, bool tight); -void inlines_to_html(gh_buf *html, inl *b); +void blocks_to_html(strbuf *html, block *b, bool tight); +void inlines_to_html(strbuf *html, inl *b); -void utf8proc_case_fold(gh_buf *dest, const unsigned char *str, int len); +void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len); #endif -- cgit v1.2.3 From 647b15968c95ec268d6d728eea73756c7ba648a8 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 4 Sep 2014 18:42:49 +0200 Subject: Rename inl --- src/stmd.h | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 2e86f3a..9ed33ec 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -10,20 +10,30 @@ #define VERSION "0.1" #define CODE_INDENT 4 -typedef struct Inline { - enum { INL_STRING, INL_SOFTBREAK, INL_LINEBREAK, INL_CODE, INL_RAW_HTML, INL_ENTITY, - INL_EMPH, INL_STRONG, INL_LINK, INL_IMAGE } tag; +struct inl { + enum { + INL_STRING, + INL_SOFTBREAK, + INL_LINEBREAK, + INL_CODE, + INL_RAW_HTML, + INL_ENTITY, + INL_EMPH, + INL_STRONG, + INL_LINK, + INL_IMAGE + } tag; union { chunk literal; - struct Inline *inlines; + struct inl *inlines; struct { - struct Inline *label; + struct inl *label; unsigned char *url; unsigned char *title; } linkable; } content; - struct Inline *next; -} inl; + struct inl *next; +}; typedef struct Reference { unsigned char *label; @@ -77,7 +87,7 @@ typedef struct Block { struct Block* parent; struct Block* top; strbuf string_content; - inl* inline_content; + struct inl* inline_content; union { struct ListData list_data; struct FencedCodeData fenced_code_data; @@ -88,8 +98,8 @@ typedef struct Block { struct Block * prev; } block; -inl* parse_inlines(strbuf *input, reference** refmap); -void free_inlines(inl* e); +struct inl* parse_inlines(strbuf *input, reference** refmap); +void free_inlines(struct inl* e); int parse_reference(strbuf *input, reference** refmap); void free_reference(reference *ref); @@ -106,11 +116,11 @@ void free_blocks(block* e); extern block *stmd_parse_document(const unsigned char *buffer, size_t len); extern block *stmd_parse_file(FILE *f); -void print_inlines(inl* ils, int indent); +void print_inlines(struct inl* ils, int indent); void print_blocks(block* blk, int indent); void blocks_to_html(strbuf *html, block *b, bool tight); -void inlines_to_html(strbuf *html, inl *b); +void inlines_to_html(strbuf *html, struct inl *b); void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len); -- cgit v1.2.3 From 9e4855365b920c2a80b0f1ab6937280f0b504334 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 4 Sep 2014 18:45:44 +0200 Subject: Rename `inl` --- src/stmd.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 9ed33ec..dbc8c8c 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -10,7 +10,7 @@ #define VERSION "0.1" #define CODE_INDENT 4 -struct inl { +struct node_inl { enum { INL_STRING, INL_SOFTBREAK, @@ -25,22 +25,26 @@ struct inl { } tag; union { chunk literal; - struct inl *inlines; + struct node_inl *inlines; struct { - struct inl *label; + struct node_inl *label; unsigned char *url; unsigned char *title; } linkable; } content; - struct inl *next; + struct node_inl *next; }; -typedef struct Reference { +typedef struct node_inl node_inl; + +struct reference { unsigned char *label; unsigned char *url; unsigned char *title; - UT_hash_handle hh; // used by uthash -} reference; + UT_hash_handle hh; // used by uthash +}; + +typedef struct reference reference; // Types for blocks @@ -87,7 +91,7 @@ typedef struct Block { struct Block* parent; struct Block* top; strbuf string_content; - struct inl* inline_content; + node_inl* inline_content; union { struct ListData list_data; struct FencedCodeData fenced_code_data; @@ -98,8 +102,8 @@ typedef struct Block { struct Block * prev; } block; -struct inl* parse_inlines(strbuf *input, reference** refmap); -void free_inlines(struct inl* e); +node_inl* parse_inlines(strbuf *input, reference** refmap); +void free_inlines(node_inl* e); int parse_reference(strbuf *input, reference** refmap); void free_reference(reference *ref); @@ -116,11 +120,11 @@ void free_blocks(block* e); extern block *stmd_parse_document(const unsigned char *buffer, size_t len); extern block *stmd_parse_file(FILE *f); -void print_inlines(struct inl* ils, int indent); +void print_inlines(node_inl* ils, int indent); void print_blocks(block* blk, int indent); void blocks_to_html(strbuf *html, block *b, bool tight); -void inlines_to_html(strbuf *html, struct inl *b); +void inlines_to_html(strbuf *html, node_inl *b); void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len); -- cgit v1.2.3 From 19ba82d7a30bd999a25fc303a8516056880abc9d Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 4 Sep 2014 18:49:33 +0200 Subject: Rename node_block --- src/stmd.h | 57 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index dbc8c8c..957ab03 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -67,29 +67,30 @@ struct FencedCodeData { strbuf info; }; -typedef struct Block { - enum { document, - block_quote, - list, - list_item, - fenced_code, - indented_code, - html_block, - paragraph, - atx_header, - setext_header, - hrule, - reference_def +struct node_block { + enum { + document, + block_quote, + list, + list_item, + fenced_code, + indented_code, + html_block, + paragraph, + atx_header, + setext_header, + hrule, + reference_def } tag; int start_line; int start_column; int end_line; bool open; bool last_line_blank; - struct Block* children; - struct Block* last_child; - struct Block* parent; - struct Block* top; + struct node_block* children; + struct node_block* last_child; + struct node_block* parent; + struct node_block* top; strbuf string_content; node_inl* inline_content; union { @@ -98,9 +99,11 @@ typedef struct Block { int header_level; reference** refmap; } attributes; - struct Block * next; - struct Block * prev; -} block; + struct node_block * next; + struct node_block * prev; +}; + +typedef struct node_block node_block; node_inl* parse_inlines(strbuf *input, reference** refmap); void free_inlines(node_inl* e); @@ -112,18 +115,18 @@ void free_reference_map(reference **refmap); void add_reference(reference** refmap, reference* ref); void unescape_buffer(strbuf *buf); -extern block* make_document(); -extern block* add_child(block* parent, +extern node_block* make_document(); +extern node_block* add_child(node_block* parent, int block_type, int start_line, int start_column); -void free_blocks(block* e); +void free_blocks(node_block* e); -extern block *stmd_parse_document(const unsigned char *buffer, size_t len); -extern block *stmd_parse_file(FILE *f); +extern node_block *stmd_parse_document(const unsigned char *buffer, size_t len); +extern node_block *stmd_parse_file(FILE *f); void print_inlines(node_inl* ils, int indent); -void print_blocks(block* blk, int indent); +void print_blocks(node_block* blk, int indent); -void blocks_to_html(strbuf *html, block *b, bool tight); +void blocks_to_html(strbuf *html, node_block *b, bool tight); void inlines_to_html(strbuf *html, node_inl *b); void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len); -- cgit v1.2.3 From 806ff17755c90579afc68914b251b80e2f8c4b77 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 4 Sep 2014 18:56:52 +0200 Subject: Rename block literals --- src/stmd.h | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 957ab03..65063fa 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -67,30 +67,29 @@ struct FencedCodeData { strbuf info; }; -struct node_block { - enum { - document, - block_quote, - list, - list_item, - fenced_code, - indented_code, - html_block, - paragraph, - atx_header, - setext_header, - hrule, - reference_def +typedef struct Block { + enum { BLOCK_DOCUMENT, + BLOCK_BQUOTE, + BLOCK_LIST, + BLOCK_LIST_ITEM, + BLOCK_FENCED_CODE, + BLOCK_INDENTED_CODE, + BLOCK_HTML, + BLOCK_PARAGRAPH, + BLOCK_ATX_HEADER, + BLOCK_SETEXT_HEADER, + BLOCK_HRULE, + BLOCK_REFERENCE_DEF } tag; int start_line; int start_column; int end_line; bool open; bool last_line_blank; - struct node_block* children; - struct node_block* last_child; - struct node_block* parent; - struct node_block* top; + struct Block* children; + struct Block* last_child; + struct Block* parent; + struct Block* top; strbuf string_content; node_inl* inline_content; union { @@ -99,11 +98,9 @@ struct node_block { int header_level; reference** refmap; } attributes; - struct node_block * next; - struct node_block * prev; -}; - -typedef struct node_block node_block; + struct Block * next; + struct Block * prev; +} node_block; node_inl* parse_inlines(strbuf *input, reference** refmap); void free_inlines(node_inl* e); -- cgit v1.2.3 From 8308ed0259a9ee02c55070db656b389c7b4be71d Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 4 Sep 2014 19:09:23 +0200 Subject: Formatting --- src/stmd.h | 101 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 47 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 65063fa..be65371 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -49,58 +49,65 @@ typedef struct reference reference; // Types for blocks struct ListData { - enum { bullet, - ordered } list_type; - int marker_offset; - int padding; - int start; - enum { period, - parens } delimiter; - unsigned char bullet_char; - bool tight; + enum { + bullet, + ordered + } list_type; + int marker_offset; + int padding; + int start; + enum { + period, + parens + } delimiter; + unsigned char bullet_char; + bool tight; }; struct FencedCodeData { - int fence_length; - int fence_offset; - char fence_char; - strbuf info; + int fence_length; + int fence_offset; + char fence_char; + strbuf info; +}; + +struct node_block { + enum { + BLOCK_DOCUMENT, + BLOCK_BQUOTE, + BLOCK_LIST, + BLOCK_LIST_ITEM, + BLOCK_FENCED_CODE, + BLOCK_INDENTED_CODE, + BLOCK_HTML, + BLOCK_PARAGRAPH, + BLOCK_ATX_HEADER, + BLOCK_SETEXT_HEADER, + BLOCK_HRULE, + BLOCK_REFERENCE_DEF + } tag; + int start_line; + int start_column; + int end_line; + bool open; + bool last_line_blank; + struct node_block* children; + struct node_block* last_child; + struct node_block* parent; + struct node_block* top; + strbuf string_content; + node_inl* inline_content; + union { + struct ListData list_data; + struct FencedCodeData fenced_code_data; + int header_level; + reference** refmap; + } attributes; + struct node_block * next; + struct node_block * prev; }; -typedef struct Block { - enum { BLOCK_DOCUMENT, - BLOCK_BQUOTE, - BLOCK_LIST, - BLOCK_LIST_ITEM, - BLOCK_FENCED_CODE, - BLOCK_INDENTED_CODE, - BLOCK_HTML, - BLOCK_PARAGRAPH, - BLOCK_ATX_HEADER, - BLOCK_SETEXT_HEADER, - BLOCK_HRULE, - BLOCK_REFERENCE_DEF - } tag; - int start_line; - int start_column; - int end_line; - bool open; - bool last_line_blank; - struct Block* children; - struct Block* last_child; - struct Block* parent; - struct Block* top; - strbuf string_content; - node_inl* inline_content; - union { - struct ListData list_data; - struct FencedCodeData fenced_code_data; - int header_level; - reference** refmap; - } attributes; - struct Block * next; - struct Block * prev; -} node_block; +typedef struct node_block node_block; node_inl* parse_inlines(strbuf *input, reference** refmap); void free_inlines(node_inl* e); -- cgit v1.2.3 From 61e3e606e64221eaa5cf3d83dc598d5a42818d10 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Sat, 6 Sep 2014 20:48:05 +0200 Subject: UTF8-aware detabbing and entity handling --- src/stmd.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index be65371..c80eeda 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -17,7 +17,6 @@ struct node_inl { INL_LINEBREAK, INL_CODE, INL_RAW_HTML, - INL_ENTITY, INL_EMPH, INL_STRONG, INL_LINK, @@ -133,6 +132,4 @@ void print_blocks(node_block* blk, int indent); void blocks_to_html(strbuf *html, node_block *b, bool tight); void inlines_to_html(strbuf *html, node_inl *b); -void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len); - #endif -- cgit v1.2.3 From 7426f9ae60272a19bd4611b8579647118033a1e6 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Sun, 7 Sep 2014 22:48:33 +0200 Subject: Abstract the Block union --- src/stmd.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index c80eeda..21a86b0 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -96,14 +96,20 @@ struct node_block { struct node_block* top; strbuf string_content; node_inl* inline_content; + union { - struct ListData list_data; - struct FencedCodeData fenced_code_data; - int header_level; - reference** refmap; - } attributes; - struct node_block * next; - struct node_block * prev; + struct ListData list; + struct FencedCodeData code; + struct { + int level; + } header; + struct { + reference** refmap; + } document; + } as; + + struct node_block *next; + struct node_block *prev; }; typedef struct node_block node_block; -- cgit v1.2.3 From 94a79a605f3e76a43f1f87a5044f6761b99e5ca5 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Wed, 10 Sep 2014 18:33:27 +0200 Subject: Cleanup reference implementation --- src/stmd.h | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 21a86b0..4e21e6c 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -5,7 +5,7 @@ #include #include "buffer.h" #include "chunk.h" -#include "uthash.h" +#include "references.h" #define VERSION "0.1" #define CODE_INDENT 4 @@ -36,17 +36,7 @@ struct node_inl { typedef struct node_inl node_inl; -struct reference { - unsigned char *label; - unsigned char *url; - unsigned char *title; - UT_hash_handle hh; // used by uthash -}; - -typedef struct reference reference; - // Types for blocks - struct ListData { enum { bullet, @@ -104,7 +94,7 @@ struct node_block { int level; } header; struct { - reference** refmap; + reference_map *refmap; } document; } as; @@ -114,14 +104,10 @@ struct node_block { typedef struct node_block node_block; -node_inl* parse_inlines(strbuf *input, reference** refmap); +node_inl* parse_inlines(strbuf *input, reference_map *refmap); void free_inlines(node_inl* e); -int parse_reference(strbuf *input, reference** refmap); -void free_reference(reference *ref); -void free_reference_map(reference **refmap); - -void add_reference(reference** refmap, reference* ref); +int parse_reference_inline(strbuf *input, reference_map *refmap); void unescape_buffer(strbuf *buf); extern node_block* make_document(); @@ -138,4 +124,8 @@ void print_blocks(node_block* blk, int indent); void blocks_to_html(strbuf *html, node_block *b, bool tight); void inlines_to_html(strbuf *html, node_inl *b); +unsigned char *clean_url(chunk *url); +unsigned char *clean_autolink(chunk *url, int is_email); +unsigned char *clean_title(chunk *title); + #endif -- cgit v1.2.3 From 118e3d3c39242225baa876319cdbfbb1adadc77b Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 15 Sep 2014 15:28:49 +0200 Subject: Cleanup external APIs --- src/stmd.h | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 4e21e6c..c6473a6 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -104,28 +104,12 @@ struct node_block { typedef struct node_block node_block; -node_inl* parse_inlines(strbuf *input, reference_map *refmap); -void free_inlines(node_inl* e); +node_block *stmd_parse_document(const unsigned char *buffer, size_t len); +node_block *stmd_parse_file(FILE *f); -int parse_reference_inline(strbuf *input, reference_map *refmap); -void unescape_buffer(strbuf *buf); +void stmd_free_nodes(node_block *e); -extern node_block* make_document(); -extern node_block* add_child(node_block* parent, - int block_type, int start_line, int start_column); -void free_blocks(node_block* e); - -extern node_block *stmd_parse_document(const unsigned char *buffer, size_t len); -extern node_block *stmd_parse_file(FILE *f); - -void print_inlines(node_inl* ils, int indent); -void print_blocks(node_block* blk, int indent); - -void blocks_to_html(strbuf *html, node_block *b, bool tight); -void inlines_to_html(strbuf *html, node_inl *b); - -unsigned char *clean_url(chunk *url); -unsigned char *clean_autolink(chunk *url, int is_email); -unsigned char *clean_title(chunk *title); +void stmd_debug_print(node_block *root); +void stmd_render_html(strbuf *html, node_block *root); #endif -- cgit v1.2.3