summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/blocks.c8
-rw-r--r--src/buffer.h67
-rw-r--r--src/chunk.h23
-rw-r--r--src/cmark.c1
-rw-r--r--src/cmark.h14
-rw-r--r--src/inlines.c24
-rw-r--r--src/inlines.h7
-rw-r--r--src/parser.h1
-rw-r--r--src/references.c31
-rw-r--r--src/references.h9
10 files changed, 77 insertions, 108 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 6f995b3..09a9306 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -49,7 +49,7 @@ cmark_doc_parser *cmark_new_doc_parser()
strbuf *line = (strbuf*)malloc(sizeof(strbuf));
cmark_strbuf_init(line, 256);
- parser->refmap = reference_map_new();
+ parser->refmap = cmark_reference_map_new();
parser->root = document;
parser->current = document;
parser->line_number = 0;
@@ -184,7 +184,7 @@ static void finalize(cmark_doc_parser *parser, cmark_node* b, int line_number)
case NODE_PARAGRAPH:
pos = 0;
while (strbuf_at(&b->string_content, 0) == '[' &&
- (pos = parse_reference_inline(&b->string_content, parser->refmap))) {
+ (pos = cmark_parse_reference_inline(&b->string_content, parser->refmap))) {
strbuf_drop(&b->string_content, pos);
}
@@ -285,7 +285,7 @@ typedef struct BlockStack {
// Walk through cmark_node and all children, recursively, parsing
// string content into inline content where appropriate.
-static void process_inlines(cmark_node* cur, reference_map *refmap)
+static void process_inlines(cmark_node* cur, cmark_reference_map *refmap)
{
block_stack* stack = NULL;
block_stack* newstack = NULL;
@@ -294,7 +294,7 @@ static void process_inlines(cmark_node* cur, reference_map *refmap)
switch (cur->type) {
case NODE_PARAGRAPH:
case NODE_HEADER:
- parse_inlines(cur, refmap);
+ cmark_parse_inlines(cur, refmap);
break;
default:
diff --git a/src/buffer.h b/src/buffer.h
index be888e1..7401b22 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -136,40 +136,39 @@ void cmark_strbuf_normalize_whitespace(cmark_strbuf *s);
CMARK_EXPORT
void cmark_strbuf_unescape(cmark_strbuf *s);
-#ifndef CMARK_NO_SHORT_NAMES
- #define strbuf cmark_strbuf
- #define strbuf__initbuf cmark_strbuf__initbuf
- #define strbuf__oom cmark_strbuf__oom
- #define GH_BUF_INIT CMARK_GH_BUF_INIT
- #define strbuf_init cmark_strbuf_init
- #define strbuf_try_grow cmark_strbuf_try_grow
- #define strbuf_grow cmark_strbuf_grow
- #define strbuf_free cmark_strbuf_free
- #define strbuf_swap cmark_strbuf_swap
- #define strbuf_oom cmark_strbuf_oom
- #define strbuf_len cmark_strbuf_len
- #define strbuf_cmp cmark_strbuf_cmp
- #define strbuf_attach cmark_strbuf_attach
- #define strbuf_detach cmark_strbuf_detach
- #define strbuf_copy_cstr cmark_strbuf_copy_cstr
- #define strbuf_at cmark_strbuf_at
- #define strbuf_set cmark_strbuf_set
- #define strbuf_sets cmark_strbuf_sets
- #define strbuf_putc cmark_strbuf_putc
- #define strbuf_put cmark_strbuf_put
- #define strbuf_puts cmark_strbuf_puts
- #define strbuf_printf cmark_strbuf_printf
- #define strbuf_vprintf cmark_strbuf_vprintf
- #define strbuf_clear cmark_strbuf_clear
- #define strbuf_strchr cmark_strbuf_strchr
- #define strbuf_strrchr cmark_strbuf_strrchr
- #define strbuf_drop cmark_strbuf_drop
- #define strbuf_truncate cmark_strbuf_truncate
- #define strbuf_rtrim cmark_strbuf_rtrim
- #define strbuf_trim cmark_strbuf_trim
- #define strbuf_normalize_whitespace cmark_strbuf_normalize_whitespace
- #define strbuf_unescape cmark_strbuf_unescape
-#endif
+// Convenience macros
+#define strbuf cmark_strbuf
+#define strbuf__initbuf cmark_strbuf__initbuf
+#define strbuf__oom cmark_strbuf__oom
+#define GH_BUF_INIT CMARK_GH_BUF_INIT
+#define strbuf_init cmark_strbuf_init
+#define strbuf_try_grow cmark_strbuf_try_grow
+#define strbuf_grow cmark_strbuf_grow
+#define strbuf_free cmark_strbuf_free
+#define strbuf_swap cmark_strbuf_swap
+#define strbuf_oom cmark_strbuf_oom
+#define strbuf_len cmark_strbuf_len
+#define strbuf_cmp cmark_strbuf_cmp
+#define strbuf_attach cmark_strbuf_attach
+#define strbuf_detach cmark_strbuf_detach
+#define strbuf_copy_cstr cmark_strbuf_copy_cstr
+#define strbuf_at cmark_strbuf_at
+#define strbuf_set cmark_strbuf_set
+#define strbuf_sets cmark_strbuf_sets
+#define strbuf_putc cmark_strbuf_putc
+#define strbuf_put cmark_strbuf_put
+#define strbuf_puts cmark_strbuf_puts
+#define strbuf_printf cmark_strbuf_printf
+#define strbuf_vprintf cmark_strbuf_vprintf
+#define strbuf_clear cmark_strbuf_clear
+#define strbuf_strchr cmark_strbuf_strchr
+#define strbuf_strrchr cmark_strbuf_strrchr
+#define strbuf_drop cmark_strbuf_drop
+#define strbuf_truncate cmark_strbuf_truncate
+#define strbuf_rtrim cmark_strbuf_rtrim
+#define strbuf_trim cmark_strbuf_trim
+#define strbuf_normalize_whitespace cmark_strbuf_normalize_whitespace
+#define strbuf_unescape cmark_strbuf_unescape
#ifdef __cplusplus
}
diff --git a/src/chunk.h b/src/chunk.h
index 7a1dbc3..22594b1 100644
--- a/src/chunk.h
+++ b/src/chunk.h
@@ -107,17 +107,16 @@ static inline cmark_chunk cmark_chunk_buf_detach(cmark_strbuf *buf)
return c;
}
-#ifndef CMARK_NO_SHORT_NAMES
- #define chunk cmark_chunk
- #define chunk_free cmark_chunk_free
- #define chunk_ltrim cmark_chunk_ltrim
- #define chunk_rtrim cmark_chunk_rtrim
- #define chunk_trim cmark_chunk_trim
- #define chunk_strchr cmark_chunk_strchr
- #define chunk_to_cstr cmark_chunk_to_cstr
- #define chunk_literal cmark_chunk_literal
- #define chunk_dup cmark_chunk_dup
- #define chunk_buf_detach cmark_chunk_buf_detach
-#endif
+// Convenience macros
+#define chunk cmark_chunk
+#define chunk_free cmark_chunk_free
+#define chunk_ltrim cmark_chunk_ltrim
+#define chunk_rtrim cmark_chunk_rtrim
+#define chunk_trim cmark_chunk_trim
+#define chunk_strchr cmark_chunk_strchr
+#define chunk_to_cstr cmark_chunk_to_cstr
+#define chunk_literal cmark_chunk_literal
+#define chunk_dup cmark_chunk_dup
+#define chunk_buf_detach cmark_chunk_buf_detach
#endif
diff --git a/src/cmark.c b/src/cmark.c
index 273a37b..945e392 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -2,7 +2,6 @@
#include <assert.h>
#include <stdio.h>
#include "node.h"
-#include "references.h"
#include "html/houdini.h"
#include "cmark.h"
#include "buffer.h"
diff --git a/src/cmark.h b/src/cmark.h
index 6105332..12da846 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -218,20 +218,6 @@ char *cmark_markdown_to_html(const char *text, int len);
#define ORDERED_LIST CMARK_ORDERED_LIST
#define PERIOD_DELIM CMARK_PERIOD_DELIM
#define PAREN_DELIM CMARK_PAREN_DELIM
- #define free_simple cmark_free_simple
- #define free_blocks cmark_free_blocks
- #define doc_parser cmark_doc_parser
- #define new_doc_parser cmark_new_doc_parser
- #define free_doc_parser cmark_free_doc_parser
- #define process_line cmark_process_line
- #define finish cmark_finish
- #define block_next cmark_block_next
- #define block_previous cmark_block_previous
- #define block_parent cmark_block_parent
- #define block_children cmark_block_children
- #define block_delete cmark_block_delete
- #define block_insert_before cmark_block_insert_before
- #define block_insert_after cmark_block_insert_after
#endif
#ifdef __cplusplus
diff --git a/src/inlines.c b/src/inlines.c
index 060b536..49dc781 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -37,13 +37,14 @@ typedef struct DelimiterStack {
typedef struct Subject {
chunk input;
int pos;
- reference_map *refmap;
+ cmark_reference_map *refmap;
delimiter_stack *delimiters;
} subject;
static int parse_inline(subject* subj, cmark_node * parent);
-static void subject_from_buf(subject *e, strbuf *buffer, reference_map *refmap);
+static void subject_from_buf(subject *e, strbuf *buffer,
+ cmark_reference_map *refmap);
static int subject_find_special_char(subject *subj);
static unsigned char *cmark_clean_autolink(chunk *url, int is_email)
@@ -154,7 +155,8 @@ static unsigned char *bufdup(const unsigned char *buf)
return new_buf;
}
-static void subject_from_buf(subject *e, strbuf *buffer, reference_map *refmap)
+static void subject_from_buf(subject *e, strbuf *buffer,
+ cmark_reference_map *refmap)
{
e->input.data = buffer->ptr;
e->input.len = buffer->size;
@@ -514,7 +516,7 @@ static cmark_node *make_str_with_entities(chunk *content)
// Clean a URL: remove surrounding whitespace and surrounding <>,
// and remove \ that escape punctuation.
-unsigned char *clean_url(chunk *url)
+unsigned char *cmark_clean_url(chunk *url)
{
strbuf buf = GH_BUF_INIT;
@@ -533,7 +535,7 @@ unsigned char *clean_url(chunk *url)
return strbuf_detach(&buf);
}
-unsigned char *clean_title(chunk *title)
+unsigned char *cmark_clean_title(chunk *title)
{
strbuf buf = GH_BUF_INIT;
unsigned char first, last;
@@ -649,7 +651,7 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent)
int starturl, endurl, starttitle, endtitle, endall;
int n;
int sps;
- reference *ref;
+ cmark_reference *ref;
bool is_image = false;
chunk urlchunk, titlechunk;
unsigned char *url, *title;
@@ -703,8 +705,8 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent)
urlchunk = chunk_dup(&subj->input, starturl, endurl - starturl);
titlechunk = chunk_dup(&subj->input, starttitle, endtitle - starttitle);
- url = clean_url(&urlchunk);
- title = clean_title(&titlechunk);
+ url = cmark_clean_url(&urlchunk);
+ title = cmark_clean_title(&titlechunk);
chunk_free(&urlchunk);
chunk_free(&titlechunk);
goto match;
@@ -731,7 +733,7 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent)
subj->pos = initial_pos;
}
- ref = reference_lookup(subj->refmap, &raw_label);
+ ref = cmark_reference_lookup(subj->refmap, &raw_label);
chunk_free(&raw_label);
if (ref != NULL) { // found
@@ -933,7 +935,7 @@ static void spnl(subject* subj)
// Modify refmap if a reference is encountered.
// Return 0 if no reference found, otherwise position of subject
// after reference is parsed.
-int parse_reference_inline(strbuf *input, reference_map *refmap)
+int cmark_parse_reference_inline(strbuf *input, cmark_reference_map *refmap)
{
subject subj;
@@ -988,6 +990,6 @@ int parse_reference_inline(strbuf *input, reference_map *refmap)
return 0;
}
// insert reference into refmap
- reference_create(refmap, &lab, &url, &title);
+ cmark_reference_create(refmap, &lab, &url, &title);
return subj.pos;
}
diff --git a/src/inlines.h b/src/inlines.h
index 92b3b7a..d2ccfb4 100644
--- a/src/inlines.h
+++ b/src/inlines.h
@@ -12,13 +12,6 @@ void cmark_parse_inlines(cmark_node* parent, cmark_reference_map *refmap);
int cmark_parse_reference_inline(cmark_strbuf *input, cmark_reference_map *refmap);
-#ifndef CMARK_NO_SHORT_NAMES
- #define parse_inlines cmark_parse_inlines
- #define parse_reference_inline cmark_parse_reference_inline
- #define clean_url cmark_clean_url
- #define clean_title cmark_clean_title
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/src/parser.h b/src/parser.h
index 4bbea09..bbbc3b1 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -3,7 +3,6 @@
#include <stdio.h>
#include "node.h"
-#include "references.h"
#include "buffer.h"
#ifdef __cplusplus
diff --git a/src/references.c b/src/references.c
index 1738de1..2b1d0a7 100644
--- a/src/references.c
+++ b/src/references.c
@@ -16,7 +16,7 @@ refhash(const unsigned char *link_ref)
return hash;
}
-static void reference_free(reference *ref)
+static void reference_free(cmark_reference *ref)
{
if(ref != NULL) {
free(ref->label);
@@ -56,9 +56,9 @@ static unsigned char *normalize_reference(chunk *ref)
return result;
}
-static void add_reference(reference_map *map, reference* ref)
+static void add_reference(cmark_reference_map *map, cmark_reference* ref)
{
- reference *t = ref->next = map->table[ref->hash % REFMAP_SIZE];
+ cmark_reference *t = ref->next = map->table[ref->hash % REFMAP_SIZE];
while (t) {
if (t->hash == ref->hash &&
@@ -73,21 +73,22 @@ static void add_reference(reference_map *map, reference* ref)
map->table[ref->hash % REFMAP_SIZE] = ref;
}
-extern void reference_create(reference_map *map, chunk *label, chunk *url, chunk *title)
+void cmark_reference_create(cmark_reference_map *map, chunk *label, chunk *url,
+ chunk *title)
{
- reference *ref;
+ cmark_reference *ref;
unsigned char *reflabel = normalize_reference(label);
/* empty reference name, or composed from only whitespace */
if (reflabel == NULL)
return;
- ref = (reference *)calloc(1, sizeof(*ref));
+ ref = (cmark_reference *)calloc(1, sizeof(*ref));
if(ref != NULL) {
ref->label = reflabel;
ref->hash = refhash(ref->label);
- ref->url = clean_url(url);
- ref->title = clean_title(title);
+ ref->url = cmark_clean_url(url);
+ ref->title = cmark_clean_title(title);
ref->next = NULL;
add_reference(map, ref);
@@ -96,9 +97,9 @@ extern void reference_create(reference_map *map, chunk *label, chunk *url, chunk
// Returns reference if refmap contains a reference with matching
// label, otherwise NULL.
-reference* reference_lookup(reference_map *map, chunk *label)
+cmark_reference* cmark_reference_lookup(cmark_reference_map *map, chunk *label)
{
- reference *ref = NULL;
+ cmark_reference *ref = NULL;
unsigned char *norm;
unsigned int hash;
@@ -126,7 +127,7 @@ reference* reference_lookup(reference_map *map, chunk *label)
return ref;
}
-void reference_map_free(reference_map *map)
+void cmark_reference_map_free(cmark_reference_map *map)
{
unsigned int i;
@@ -134,8 +135,8 @@ void reference_map_free(reference_map *map)
return;
for (i = 0; i < REFMAP_SIZE; ++i) {
- reference *ref = map->table[i];
- reference *next;
+ cmark_reference *ref = map->table[i];
+ cmark_reference *next;
while (ref) {
next = ref->next;
@@ -147,7 +148,7 @@ void reference_map_free(reference_map *map)
free(map);
}
-reference_map *reference_map_new(void)
+cmark_reference_map *cmark_reference_map_new(void)
{
- return (reference_map *)calloc(1, sizeof(reference_map));
+ return (cmark_reference_map *)calloc(1, sizeof(cmark_reference_map));
}
diff --git a/src/references.h b/src/references.h
index 572178d..69325bb 100644
--- a/src/references.h
+++ b/src/references.h
@@ -30,15 +30,6 @@ void cmark_reference_map_free(cmark_reference_map *map);
cmark_reference* cmark_reference_lookup(cmark_reference_map *map, cmark_chunk *label);
extern void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label, cmark_chunk *url, cmark_chunk *title);
-#ifndef CMARK_NO_SHORT_NAMES
- #define reference cmark_reference
- #define reference_map cmark_reference_map
- #define reference_map_new cmark_reference_map_new
- #define reference_map_free cmark_reference_map_free
- #define reference_lookup cmark_reference_lookup
- #define reference_create cmark_reference_create
-#endif
-
#ifdef __cplusplus
}
#endif