aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2014-11-17 21:22:49 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-17 21:43:47 -0800
commit4cf3275ee16255a8fa9a5c3e290a152d1705fc3a (patch)
tree3d6565a30c9b89b41612185b8956720a6d004eda /src
parentc2e63df630fac01b78859b4038be16cef26fe9be (diff)
Move inline-related stuff to inlines.c
Diffstat (limited to 'src')
-rw-r--r--src/ast.h80
-rw-r--r--src/cmark.c16
-rw-r--r--src/inlines.c77
3 files changed, 77 insertions, 96 deletions
diff --git a/src/ast.h b/src/ast.h
index 168c926..bd9b342 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -39,86 +39,6 @@ struct cmark_doc_parser {
cmark_strbuf *curline;
};
-unsigned char *cmark_clean_autolink(chunk *url, int is_email);
-
-static inline cmark_node *cmark_make_link(cmark_node *label, unsigned char *url, unsigned char *title)
-{
- cmark_node* e = (cmark_node *)calloc(1, sizeof(*e));
- if(e != NULL) {
- e->type = CMARK_NODE_LINK;
- e->as.link.label = label;
- e->as.link.url = url;
- e->as.link.title = title;
- e->next = NULL;
- }
- return e;
-}
-
-static inline cmark_node* cmark_make_autolink(cmark_node* label, cmark_chunk url, int is_email)
-{
- return cmark_make_link(label, cmark_clean_autolink(&url, is_email), NULL);
-}
-
-static inline cmark_node* cmark_make_inlines(cmark_node_type t, cmark_node* contents)
-{
- cmark_node * e = (cmark_node *)calloc(1, sizeof(*e));
- if(e != NULL) {
- e->type = t;
- e->first_child = contents;
- e->next = NULL;
- }
- return e;
-}
-
-// Create an inline with a literal string value.
-static inline cmark_node* cmark_make_literal(cmark_node_type t, cmark_chunk s)
-{
- cmark_node * e = (cmark_node *)calloc(1, sizeof(*e));
- if(e != NULL) {
- e->type = t;
- e->as.literal = s;
- e->next = NULL;
- }
- return e;
-}
-
-// Create an inline with no value.
-static inline cmark_node* cmark_make_simple(cmark_node_type t)
-{
- cmark_node* e = (cmark_node *)calloc(1, sizeof(*e));
- if(e != NULL) {
- e->type = t;
- e->next = NULL;
- }
- return e;
-}
-
-// Macros for creating various kinds of simple.
-#define cmark_make_str(s) cmark_make_literal(CMARK_NODE_STRING, s)
-#define cmark_make_code(s) cmark_make_literal(CMARK_NODE_INLINE_CODE, s)
-#define cmark_make_raw_html(s) cmark_make_literal(CMARK_NODE_INLINE_HTML, s)
-#define cmark_make_linebreak() cmark_make_simple(CMARK_NODE_LINEBREAK)
-#define cmark_make_softbreak() cmark_make_simple(CMARK_NODE_SOFTBREAK)
-#define cmark_make_emph(contents) cmark_make_inlines(CMARK_NODE_EMPH, contents)
-#define cmark_make_strong(contents) cmark_make_inlines(CMARK_NODE_STRONG, contents)
-
-
-
-#ifndef CMARK_NO_SHORT_NAMES
- #define make_link cmark_make_link
- #define make_autolink cmark_make_autolink
- #define make_str cmark_make_str
- #define make_code cmark_make_code
- #define make_raw_html cmark_make_raw_html
- #define make_linebreak cmark_make_linebreak
- #define make_softbreak cmark_make_softbreak
- #define make_emph cmark_make_emph
- #define make_strong cmark_make_strong
- #define make_simple cmark_make_simple
- #define make_literal cmark_make_literal
- #define make_inlines cmark_make_inlines
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/src/cmark.c b/src/cmark.c
index fa9b5c8..f779e80 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -37,22 +37,6 @@ static void splice_into_list(cmark_node* e, cmark_node* children) {
return ;
}
-unsigned char *cmark_clean_autolink(chunk *url, int is_email)
-{
- strbuf buf = GH_BUF_INIT;
-
- chunk_trim(url);
-
- if (url->len == 0)
- return NULL;
-
- if (is_email)
- strbuf_puts(&buf, "mailto:");
-
- houdini_unescape_html_f(&buf, url->data, url->len);
- return strbuf_detach(&buf);
-}
-
// Free a cmark_node list and any children.
void cmark_free_nodes(cmark_node *e)
{
diff --git a/src/inlines.c b/src/inlines.c
index 313dfe5..2bfdfd5 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -14,6 +14,15 @@
#include "inlines.h"
+// Macros for creating various kinds of simple.
+#define make_str(s) make_literal(CMARK_NODE_STRING, s)
+#define make_code(s) make_literal(CMARK_NODE_INLINE_CODE, s)
+#define make_raw_html(s) make_literal(CMARK_NODE_INLINE_HTML, s)
+#define make_linebreak() make_simple(CMARK_NODE_LINEBREAK)
+#define make_softbreak() make_simple(CMARK_NODE_SOFTBREAK)
+#define make_emph(contents) make_inlines(CMARK_NODE_EMPH, contents)
+#define make_strong(contents) make_inlines(CMARK_NODE_STRONG, contents)
+
typedef struct DelimiterStack {
struct DelimiterStack *previous;
struct DelimiterStack *next;
@@ -38,6 +47,74 @@ static int parse_inline(subject* subj, cmark_node ** last);
static void subject_from_buf(subject *e, strbuf *buffer, reference_map *refmap);
static int subject_find_special_char(subject *subj);
+static unsigned char *cmark_clean_autolink(chunk *url, int is_email)
+{
+ strbuf buf = GH_BUF_INIT;
+
+ chunk_trim(url);
+
+ if (url->len == 0)
+ return NULL;
+
+ if (is_email)
+ strbuf_puts(&buf, "mailto:");
+
+ houdini_unescape_html_f(&buf, url->data, url->len);
+ return strbuf_detach(&buf);
+}
+
+static inline cmark_node *make_link(cmark_node *label, unsigned char *url, unsigned char *title)
+{
+ cmark_node* e = (cmark_node *)calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->type = CMARK_NODE_LINK;
+ e->as.link.label = label;
+ e->as.link.url = url;
+ e->as.link.title = title;
+ e->next = NULL;
+ }
+ return e;
+}
+
+static inline cmark_node* make_autolink(cmark_node* label, cmark_chunk url, int is_email)
+{
+ return make_link(label, cmark_clean_autolink(&url, is_email), NULL);
+}
+
+static inline cmark_node* make_inlines(cmark_node_type t, cmark_node* contents)
+{
+ cmark_node * e = (cmark_node *)calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->type = t;
+ e->first_child = contents;
+ e->next = NULL;
+ }
+ return e;
+}
+
+// Create an inline with a literal string value.
+static inline cmark_node* make_literal(cmark_node_type t, cmark_chunk s)
+{
+ cmark_node * e = (cmark_node *)calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->type = t;
+ e->as.literal = s;
+ e->next = NULL;
+ }
+ return e;
+}
+
+// Create an inline with no value.
+static inline cmark_node* make_simple(cmark_node_type t)
+{
+ cmark_node* e = (cmark_node *)calloc(1, sizeof(*e));
+ if(e != NULL) {
+ e->type = t;
+ e->next = NULL;
+ }
+ return e;
+}
+
static unsigned char *bufdup(const unsigned char *buf)
{
unsigned char *new_buf = NULL;