summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/ast.h163
-rw-r--r--src/blocks.c2
-rw-r--r--src/cmark.c1
-rw-r--r--src/cmark.h155
-rw-r--r--src/html/html.c1
-rw-r--r--src/inlines.c2
-rw-r--r--src/print.c1
-rw-r--r--src/references.c1
-rw-r--r--src/references.h19
10 files changed, 200 insertions, 146 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1b70584..2413acd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8)
set(LIBRARY "libcmark")
set(HEADERS
cmark.h
+ ast.h
buffer.h
chunk.h
references.h
diff --git a/src/ast.h b/src/ast.h
new file mode 100644
index 0000000..b4427c0
--- /dev/null
+++ b/src/ast.h
@@ -0,0 +1,163 @@
+#ifndef CMARK_AST_H
+#define CMARK_AST_H
+
+#include <stdbool.h>
+#include <stdio.h>
+#include "buffer.h"
+#include "chunk.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CMARK_VERSION "0.1"
+#define CMARK_CODE_INDENT 4
+#define REFMAP_SIZE 16
+#define CMARK_MAX_LINK_LABEL_LENGTH 1000
+
+struct cmark_node_inl {
+ enum {
+ CMARK_INL_STRING,
+ CMARK_INL_SOFTBREAK,
+ CMARK_INL_LINEBREAK,
+ CMARK_INL_CODE,
+ CMARK_INL_RAW_HTML,
+ CMARK_INL_EMPH,
+ CMARK_INL_STRONG,
+ CMARK_INL_LINK,
+ CMARK_INL_IMAGE
+ } tag;
+ union {
+ cmark_chunk literal;
+ struct cmark_node_inl *inlines;
+ struct {
+ struct cmark_node_inl *label;
+ unsigned char *url;
+ unsigned char *title;
+ } linkable;
+ } content;
+ struct cmark_node_inl *next;
+};
+
+struct cmark_reference {
+ struct cmark_reference *next;
+ unsigned char *label;
+ unsigned char *url;
+ unsigned char *title;
+ unsigned int hash;
+};
+
+typedef struct cmark_reference cmark_reference;
+
+struct cmark_reference_map {
+ cmark_reference *table[REFMAP_SIZE];
+};
+
+typedef struct cmark_reference_map cmark_reference_map;
+
+// Types for blocks
+struct cmark_ListData {
+ enum {
+ bullet,
+ ordered
+ } list_type;
+ int marker_offset;
+ int padding;
+ int start;
+ enum {
+ period,
+ parens
+ } delimiter;
+ unsigned char bullet_char;
+ bool tight;
+};
+
+struct cmark_FencedCodeData {
+ int fence_length;
+ int fence_offset;
+ unsigned char fence_char;
+ cmark_strbuf info;
+};
+
+struct cmark_node_block {
+ enum {
+ CMARK_BLOCK_DOCUMENT,
+ CMARK_BLOCK_BQUOTE,
+ CMARK_BLOCK_LIST,
+ CMARK_BLOCK_LIST_ITEM,
+ CMARK_BLOCK_FENCED_CODE,
+ CMARK_BLOCK_INDENTED_CODE,
+ CMARK_BLOCK_HTML,
+ CMARK_BLOCK_PARAGRAPH,
+ CMARK_BLOCK_ATX_HEADER,
+ CMARK_BLOCK_SETEXT_HEADER,
+ CMARK_BLOCK_HRULE,
+ CMARK_BLOCK_REFERENCE_DEF
+ } tag;
+ int start_line;
+ int start_column;
+ int end_line;
+ bool open;
+ bool last_line_blank;
+ struct cmark_node_block* children;
+ struct cmark_node_block* last_child;
+ struct cmark_node_block* parent;
+ struct cmark_node_block* top;
+ cmark_strbuf string_content;
+ struct cmark_node_inl* inline_content;
+
+ union {
+ struct cmark_ListData list;
+ struct cmark_FencedCodeData code;
+ struct {
+ int level;
+ } header;
+ struct {
+ cmark_reference_map *refmap;
+ } document;
+ } as;
+
+ struct cmark_node_block *next;
+ struct cmark_node_block *prev;
+};
+
+struct cmark_doc_parser {
+ struct cmark_node_block* head;
+ struct cmark_node_block* current;
+ int line_number;
+ cmark_strbuf *curline;
+};
+
+#ifndef CMARK_NO_SHORT_NAMES
+ #define node_inl cmark_node_inl
+ #define INL_STRING CMARK_INL_STRING
+ #define INL_SOFTBREAK CMARK_INL_SOFTBREAK
+ #define INL_LINEBREAK CMARK_INL_LINEBREAK
+ #define INL_CODE CMARK_INL_CODE
+ #define INL_RAW_HTML CMARK_INL_RAW_HTML
+ #define INL_EMPH CMARK_INL_EMPH
+ #define INL_STRONG CMARK_INL_STRONG
+ #define INL_LINK CMARK_INL_LINK
+ #define INL_IMAGE CMARK_INL_IMAGE
+ #define ListData cmark_ListData
+ #define FencedCodeData cmark_FencedCodeData
+ #define node_block cmark_node_block
+ #define BLOCK_DOCUMENT CMARK_BLOCK_DOCUMENT
+ #define BLOCK_BQUOTE CMARK_BLOCK_BQUOTE
+ #define BLOCK_LIST CMARK_BLOCK_LIST
+ #define BLOCK_LIST_ITEM CMARK_BLOCK_LIST_ITEM
+ #define BLOCK_FENCED_CODE CMARK_BLOCK_FENCED_CODE
+ #define BLOCK_INDENTED_CODE CMARK_BLOCK_INDENTED_CODE
+ #define BLOCK_HTML CMARK_BLOCK_HTML
+ #define BLOCK_PARAGRAPH CMARK_BLOCK_PARAGRAPH
+ #define BLOCK_ATX_HEADER CMARK_BLOCK_ATX_HEADER
+ #define BLOCK_SETEXT_HEADER CMARK_BLOCK_SETEXT_HEADER
+ #define BLOCK_HRULE CMARK_BLOCK_HRULE
+ #define BLOCK_REFERENCE_DEF CMARK_BLOCK_REFERENCE_DEF
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/blocks.c b/src/blocks.c
index 568af0a..dd6278b 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -4,7 +4,9 @@
#include <stdbool.h>
#include <ctype.h>
+#include "ast.h"
#include "cmark.h"
+#include "references.h"
#include "utf8.h"
#include "scanners.h"
#include "inlines.h"
diff --git a/src/cmark.c b/src/cmark.c
index 8f379bf..85e1adb 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -6,6 +6,7 @@
#include "html/houdini.h"
#include "cmark.h"
#include "buffer.h"
+#include "ast.h"
unsigned char *cmark_markdown_to_html(unsigned char *text, int len)
{
diff --git a/src/cmark.h b/src/cmark.h
index c8c7e8d..e28e747 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -5,8 +5,6 @@
#include <stdio.h>
#include "buffer.h"
#include "chunk.h"
-#include "references.h"
-#include "cmark_export.h"
#ifdef __cplusplus
extern "C" {
@@ -14,171 +12,72 @@ extern "C" {
#define CMARK_VERSION "0.1"
#define CMARK_CODE_INDENT 4
-
#define CMARK_MAX_LINK_LABEL_LENGTH 1000
-struct cmark_node_inl {
- enum {
- CMARK_INL_STRING,
- CMARK_INL_SOFTBREAK,
- CMARK_INL_LINEBREAK,
- CMARK_INL_CODE,
- CMARK_INL_RAW_HTML,
- CMARK_INL_EMPH,
- CMARK_INL_STRONG,
- CMARK_INL_LINK,
- CMARK_INL_IMAGE
- } tag;
- union {
- cmark_chunk literal;
- struct cmark_node_inl *inlines;
- struct {
- struct cmark_node_inl *label;
- unsigned char *url;
- unsigned char *title;
- } linkable;
- } content;
- struct cmark_node_inl *next;
-};
-
typedef struct cmark_node_inl cmark_node_inl;
-
-// Types for blocks
-struct cmark_ListData {
- enum {
- bullet,
- ordered
- } list_type;
- int marker_offset;
- int padding;
- int start;
- enum {
- period,
- parens
- } delimiter;
- unsigned char bullet_char;
- bool tight;
-};
-
-struct cmark_FencedCodeData {
- int fence_length;
- int fence_offset;
- unsigned char fence_char;
- cmark_strbuf info;
-};
-
-struct cmark_node_block {
- enum {
- CMARK_BLOCK_DOCUMENT,
- CMARK_BLOCK_BQUOTE,
- CMARK_BLOCK_LIST,
- CMARK_BLOCK_LIST_ITEM,
- CMARK_BLOCK_FENCED_CODE,
- CMARK_BLOCK_INDENTED_CODE,
- CMARK_BLOCK_HTML,
- CMARK_BLOCK_PARAGRAPH,
- CMARK_BLOCK_ATX_HEADER,
- CMARK_BLOCK_SETEXT_HEADER,
- CMARK_BLOCK_HRULE,
- CMARK_BLOCK_REFERENCE_DEF
- } tag;
- int start_line;
- int start_column;
- int end_line;
- bool open;
- bool last_line_blank;
- struct cmark_node_block* children;
- struct cmark_node_block* last_child;
- struct cmark_node_block* parent;
- struct cmark_node_block* top;
- cmark_strbuf string_content;
- cmark_node_inl* inline_content;
-
- union {
- struct cmark_ListData list;
- struct cmark_FencedCodeData code;
- struct {
- int level;
- } header;
- struct {
- cmark_reference_map *refmap;
- } document;
- } as;
-
- struct cmark_node_block *next;
- struct cmark_node_block *prev;
-};
-
typedef struct cmark_node_block cmark_node_block;
-
-struct cmark_doc_parser {
- cmark_node_block* head;
- cmark_node_block* current;
- int line_number;
- cmark_strbuf *curline;
-};
-
typedef struct cmark_doc_parser cmark_doc_parser;
CMARK_EXPORT
-void cmark_free_blocks(cmark_node_block *e);
+cmark_doc_parser *cmark_new_doc_parser();
CMARK_EXPORT
-void cmark_free_inlines(cmark_node_inl* e);
+void cmark_free_doc_parser(cmark_doc_parser *parser);
CMARK_EXPORT
-cmark_node_inl *cmark_make_link(cmark_node_inl *label, unsigned char *url, unsigned char *title);
+cmark_node_block *cmark_finish(cmark_doc_parser *parser);
CMARK_EXPORT
-cmark_node_inl* cmark_make_autolink(cmark_node_inl* label, cmark_chunk url, int is_email);
+void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer, size_t bytes);
CMARK_EXPORT
-cmark_node_inl* cmark_make_inlines(int t, cmark_node_inl* contents);
+cmark_node_block *cmark_finish(cmark_doc_parser *parser);
CMARK_EXPORT
-cmark_node_inl* cmark_make_literal(int t, cmark_chunk s);
+cmark_node_block *cmark_parse_document(const unsigned char *buffer, size_t len);
CMARK_EXPORT
-cmark_node_inl* cmark_make_simple(int t);
-
-// Macros for creating various kinds of simple.
-#define cmark_make_str(s) cmark_make_literal(INL_STRING, s)
-#define cmark_make_code(s) cmark_make_literal(INL_CODE, s)
-#define cmark_make_raw_html(s) cmark_make_literal(INL_RAW_HTML, s)
-#define cmark_make_linebreak() cmark_make_simple(INL_LINEBREAK)
-#define cmark_make_softbreak() cmark_make_simple(INL_SOFTBREAK)
-#define cmark_make_emph(contents) cmark_make_inlines(INL_EMPH, contents)
-#define cmark_make_strong(contents) cmark_make_inlines(INL_STRONG, contents)
+cmark_node_block *cmark_parse_file(FILE *f);
CMARK_EXPORT
-cmark_doc_parser *cmark_new_doc_parser();
+void cmark_debug_print(cmark_node_block *root);
CMARK_EXPORT
-void cmark_free_doc_parser(cmark_doc_parser *parser);
+void cmark_render_html(cmark_strbuf *html, cmark_node_block *root);
CMARK_EXPORT
-cmark_node_block *cmark_finish(cmark_doc_parser *parser);
+unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
CMARK_EXPORT
-void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer, size_t bytes);
+void cmark_free_blocks(cmark_node_block *e);
CMARK_EXPORT
-cmark_node_block *cmark_finish(cmark_doc_parser *parser);
+void cmark_free_inlines(cmark_node_inl* e);
CMARK_EXPORT
-cmark_node_block *cmark_parse_document(const unsigned char *buffer, size_t len);
+cmark_node_inl *cmark_make_link(cmark_node_inl *label, unsigned char *url, unsigned char *title);
CMARK_EXPORT
-cmark_node_block *cmark_parse_file(FILE *f);
+cmark_node_inl* cmark_make_autolink(cmark_node_inl* label, cmark_chunk url, int is_email);
CMARK_EXPORT
-void cmark_debug_print(cmark_node_block *root);
+cmark_node_inl* cmark_make_inlines(int t, cmark_node_inl* contents);
CMARK_EXPORT
-void cmark_render_html(cmark_strbuf *html, cmark_node_block *root);
+cmark_node_inl* cmark_make_literal(int t, cmark_chunk s);
CMARK_EXPORT
-unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
+cmark_node_inl* cmark_make_simple(int t);
+
+// Macros for creating various kinds of simple.
+#define cmark_make_str(s) cmark_make_literal(INL_STRING, s)
+#define cmark_make_code(s) cmark_make_literal(INL_CODE, s)
+#define cmark_make_raw_html(s) cmark_make_literal(INL_RAW_HTML, s)
+#define cmark_make_linebreak() cmark_make_simple(INL_LINEBREAK)
+#define cmark_make_softbreak() cmark_make_simple(INL_SOFTBREAK)
+#define cmark_make_emph(contents) cmark_make_inlines(INL_EMPH, contents)
+#define cmark_make_strong(contents) cmark_make_inlines(INL_STRONG, contents)
+
#ifndef CMARK_NO_SHORT_NAMES
#define VERSION CMARK_VERSION
diff --git a/src/html/html.c b/src/html/html.c
index 6b5d614..cd02f83 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -5,6 +5,7 @@
#include <assert.h>
#include "cmark.h"
+#include "ast.h"
#include "debug.h"
#include "html/houdini.h"
diff --git a/src/inlines.c b/src/inlines.c
index cf07586..677861f 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -4,6 +4,8 @@
#include <stdbool.h>
#include <ctype.h>
+#include "ast.h"
+#include "references.h"
#include "cmark.h"
#include "html/houdini.h"
#include "utf8.h"
diff --git a/src/print.c b/src/print.c
index b5ef056..ce387b4 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include "ast.h"
#include "cmark.h"
#include "debug.h"
diff --git a/src/references.c b/src/references.c
index e39b836..cb750c6 100644
--- a/src/references.c
+++ b/src/references.c
@@ -1,5 +1,6 @@
#include "cmark.h"
#include "utf8.h"
+#include "ast.h"
#include "references.h"
#include "inlines.h"
#include "chunk.h"
diff --git a/src/references.h b/src/references.h
index cd58614..2972576 100644
--- a/src/references.h
+++ b/src/references.h
@@ -1,25 +1,8 @@
#ifndef CMARK_REFERENCES_H
#define CMARK_REFERENCES_H
-#define REFMAP_SIZE 16
-
#include "chunk.h"
-
-struct cmark_reference {
- struct cmark_reference *next;
- unsigned char *label;
- unsigned char *url;
- unsigned char *title;
- unsigned int hash;
-};
-
-typedef struct cmark_reference cmark_reference;
-
-struct cmark_reference_map {
- cmark_reference *table[REFMAP_SIZE];
-};
-
-typedef struct cmark_reference_map cmark_reference_map;
+#include "ast.h"
cmark_reference_map *cmark_reference_map_new(void);
void cmark_reference_map_free(cmark_reference_map *map);