diff --git 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/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/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));
}