aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-22 21:32:21 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-22 21:32:21 -0800
commita71423f6ee1b77d9f79d42599ea00b4ca99f5da0 (patch)
treeb6007b211ffbedf996a7416dbbc26f6d33006913 /src
parentacac9428faa1c3193fb44b3fb0e2dd3cbdaa4ac9 (diff)
Remove distinction btw atx and setext header in AST.
Now we just have 'header' -- Setext and ATX are just two ways of forming these; it's not a semantic difference that should remain in the AST.
Diffstat (limited to 'src')
-rw-r--r--src/blocks.c23
-rw-r--r--src/cmark.h6
-rw-r--r--src/html/html.c6
-rw-r--r--src/node.c15
-rw-r--r--src/print.c6
5 files changed, 21 insertions, 35 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 2a6cdd8..57f6756 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -97,9 +97,9 @@ static inline bool can_contain(cmark_node_type parent_type, cmark_node_type chil
static inline bool accepts_lines(cmark_node_type block_type)
{
return (block_type == NODE_PARAGRAPH ||
- block_type == NODE_ATX_HEADER ||
- block_type == NODE_INDENTED_CODE ||
- block_type == NODE_FENCED_CODE);
+ block_type == NODE_HEADER ||
+ block_type == NODE_INDENTED_CODE ||
+ block_type == NODE_FENCED_CODE);
}
static void add_line(cmark_node* cmark_node, chunk *ch, int offset)
@@ -293,8 +293,7 @@ static void process_inlines(cmark_node* cur, reference_map *refmap)
while (cur != NULL) {
switch (cur->type) {
case NODE_PARAGRAPH:
- case NODE_ATX_HEADER:
- case NODE_SETEXT_HEADER:
+ case NODE_HEADER:
parse_inlines(cur, refmap);
break;
@@ -548,8 +547,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
all_matched = false;
}
- } else if (container->type == NODE_ATX_HEADER ||
- container->type == NODE_SETEXT_HEADER) {
+ } else if (container->type == NODE_HEADER) {
// a header can never contain more than one line
all_matched = false;
@@ -625,7 +623,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
} else if ((matched = scan_atx_header_start(&input, first_nonspace))) {
offset = first_nonspace + matched;
- container = add_child(parser, container, NODE_ATX_HEADER, parser->line_number, offset + 1);
+ container = add_child(parser, container, NODE_HEADER, parser->line_number, offset + 1);
int hashpos = chunk_strchr(&input, '#', first_nonspace);
int level = 0;
@@ -655,7 +653,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
strbuf_strrchr(&container->string_content, '\n',
strbuf_len(&container->string_content) - 2) < 0) {
- container->type = NODE_SETEXT_HEADER;
+ container->type = NODE_HEADER;
container->as.header.level = lev;
offset = input.len - 1;
@@ -732,7 +730,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
// on an empty list item.
container->last_line_blank = (blank &&
container->type != NODE_BLOCK_QUOTE &&
- container->type != NODE_SETEXT_HEADER &&
+ container->type != NODE_HEADER &&
container->type != NODE_FENCED_CODE &&
!(container->type == NODE_LIST_ITEM &&
container->first_child == NULL &&
@@ -791,7 +789,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
// ??? do nothing
- } else if (container->type == NODE_ATX_HEADER) {
+ } else if (container->type == NODE_HEADER) {
chop_trailing_hashtags(&input);
add_line(container, &input, first_nonspace);
@@ -802,7 +800,8 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
add_line(container, &input, first_nonspace);
- } else if (container->type != NODE_HRULE && container->type != NODE_SETEXT_HEADER) {
+ } else if (container->type != NODE_HRULE &&
+ container->type != NODE_HEADER) {
// create paragraph container for line
container = add_child(parser, container, NODE_PARAGRAPH, parser->line_number, first_nonspace + 1);
diff --git a/src/cmark.h b/src/cmark.h
index 3c185b6..b83f886 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -20,8 +20,7 @@ typedef enum {
CMARK_NODE_INDENTED_CODE,
CMARK_NODE_HTML,
CMARK_NODE_PARAGRAPH,
- CMARK_NODE_ATX_HEADER,
- CMARK_NODE_SETEXT_HEADER,
+ CMARK_NODE_HEADER,
CMARK_NODE_HRULE,
CMARK_NODE_REFERENCE_DEF,
@@ -204,8 +203,7 @@ char *cmark_markdown_to_html(const char *text, int len);
#define NODE_INDENTED_CODE CMARK_NODE_INDENTED_CODE
#define NODE_HTML CMARK_NODE_HTML
#define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH
- #define NODE_ATX_HEADER CMARK_NODE_ATX_HEADER
- #define NODE_SETEXT_HEADER CMARK_NODE_SETEXT_HEADER
+ #define NODE_HEADER CMARK_NODE_HEADER
#define NODE_HRULE CMARK_NODE_HRULE
#define NODE_REFERENCE_DEF CMARK_NODE_REFERENCE_DEF
#define NODE_STRING CMARK_NODE_STRING
diff --git a/src/html/html.c b/src/html/html.c
index 0ce4443..e6971f8 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -149,8 +149,7 @@ static void node_to_html(strbuf *html, cmark_node *node)
break;
}
- case NODE_ATX_HEADER:
- case NODE_SETEXT_HEADER:
+ case NODE_HEADER:
cr(html);
start_header[2] = '0' + cur->as.header.level;
strbuf_puts(html, start_header);
@@ -316,8 +315,7 @@ finish_node(strbuf *html, cmark_node *node, bool tight)
break;
}
- case NODE_ATX_HEADER:
- case NODE_SETEXT_HEADER:
+ case NODE_HEADER:
end_header[3] = '0' + node->as.header.level;
strbuf_puts(html, end_header);
break;
diff --git a/src/node.c b/src/node.c
index 35e19d2..3e51fec 100644
--- a/src/node.c
+++ b/src/node.c
@@ -13,8 +13,7 @@ cmark_node_new(cmark_node_type type) {
node->type = type;
switch (node->type) {
- case CMARK_NODE_ATX_HEADER:
- case CMARK_NODE_SETEXT_HEADER:
+ case CMARK_NODE_HEADER:
node->as.header.level = 1;
break;
@@ -58,8 +57,7 @@ S_type_string(cmark_node *node)
case CMARK_NODE_INDENTED_CODE: return "INDENTED_CODE";
case CMARK_NODE_HTML: return "HTML";
case CMARK_NODE_PARAGRAPH: return "PARAGRAPH";
- case CMARK_NODE_ATX_HEADER: return "ATX_HEADER";
- case CMARK_NODE_SETEXT_HEADER: return "SETEXT_HEADER";
+ case CMARK_NODE_HEADER: return "HEADER";
case CMARK_NODE_HRULE: return "HRULE";
case CMARK_NODE_REFERENCE_DEF: return "REFERENCE_DEF";
case CMARK_NODE_STRING: return "STRING";
@@ -159,8 +157,7 @@ cmark_node_set_string_content(cmark_node *node, const char *content) {
int
cmark_node_get_header_level(cmark_node *node) {
switch (node->type) {
- case CMARK_NODE_ATX_HEADER:
- case CMARK_NODE_SETEXT_HEADER:
+ case CMARK_NODE_HEADER:
return node->as.header.level;
default:
@@ -177,8 +174,7 @@ cmark_node_set_header_level(cmark_node *node, int level) {
}
switch (node->type) {
- case CMARK_NODE_ATX_HEADER:
- case CMARK_NODE_SETEXT_HEADER:
+ case CMARK_NODE_HEADER:
node->as.header.level = level;
return 1;
@@ -393,8 +389,7 @@ S_can_contain(cmark_node *node, cmark_node *child)
return child->type == CMARK_NODE_LIST_ITEM;
case CMARK_NODE_PARAGRAPH:
- case CMARK_NODE_ATX_HEADER:
- case CMARK_NODE_SETEXT_HEADER:
+ case CMARK_NODE_HEADER:
case CMARK_NODE_EMPH:
case CMARK_NODE_STRONG:
case CMARK_NODE_LINK:
diff --git a/src/print.c b/src/print.c
index b1bab4b..2064276 100644
--- a/src/print.c
+++ b/src/print.c
@@ -132,11 +132,7 @@ static void print_blocks(cmark_node* b, int indent)
}
print_blocks(b->first_child, indent + 2);
break;
- case NODE_ATX_HEADER:
- printf("atx_header (level=%d)\n", b->as.header.level);
- print_inlines(b->first_child, indent + 2);
- break;
- case NODE_SETEXT_HEADER:
+ case NODE_HEADER:
printf("setext_header (level=%d)\n", b->as.header.level);
print_inlines(b->first_child, indent + 2);
break;