summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-22 22:39:26 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-22 22:39:26 -0800
commit4570eb2bff2e1b71fa5b6408abbc69c98ff5ff24 (patch)
tree16bab9f8f34dd6fc22a1b7f27b02b7f92b2939d6 /src
parenta71423f6ee1b77d9f79d42599ea00b4ca99f5da0 (diff)
Revert "Remove distinction btw atx and setext header in AST."
This reverts commit a71423f6ee1b77d9f79d42599ea00b4ca99f5da0. Not quite sure about this change, so reverting for now. Note that we still have a distinction between fenced and indented code blocks in the AST. These two distinctions seem to stand or fall together.
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, 35 insertions, 21 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 57f6756..2a6cdd8 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_HEADER ||
- block_type == NODE_INDENTED_CODE ||
- block_type == NODE_FENCED_CODE);
+ block_type == NODE_ATX_HEADER ||
+ block_type == NODE_INDENTED_CODE ||
+ block_type == NODE_FENCED_CODE);
}
static void add_line(cmark_node* cmark_node, chunk *ch, int offset)
@@ -293,7 +293,8 @@ static void process_inlines(cmark_node* cur, reference_map *refmap)
while (cur != NULL) {
switch (cur->type) {
case NODE_PARAGRAPH:
- case NODE_HEADER:
+ case NODE_ATX_HEADER:
+ case NODE_SETEXT_HEADER:
parse_inlines(cur, refmap);
break;
@@ -547,7 +548,8 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
all_matched = false;
}
- } else if (container->type == NODE_HEADER) {
+ } else if (container->type == NODE_ATX_HEADER ||
+ container->type == NODE_SETEXT_HEADER) {
// a header can never contain more than one line
all_matched = false;
@@ -623,7 +625,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_HEADER, parser->line_number, offset + 1);
+ container = add_child(parser, container, NODE_ATX_HEADER, parser->line_number, offset + 1);
int hashpos = chunk_strchr(&input, '#', first_nonspace);
int level = 0;
@@ -653,7 +655,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_HEADER;
+ container->type = NODE_SETEXT_HEADER;
container->as.header.level = lev;
offset = input.len - 1;
@@ -730,7 +732,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_HEADER &&
+ container->type != NODE_SETEXT_HEADER &&
container->type != NODE_FENCED_CODE &&
!(container->type == NODE_LIST_ITEM &&
container->first_child == NULL &&
@@ -789,7 +791,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
// ??? do nothing
- } else if (container->type == NODE_HEADER) {
+ } else if (container->type == NODE_ATX_HEADER) {
chop_trailing_hashtags(&input);
add_line(container, &input, first_nonspace);
@@ -800,8 +802,7 @@ 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_HEADER) {
+ } else if (container->type != NODE_HRULE && container->type != NODE_SETEXT_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 b83f886..3c185b6 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -20,7 +20,8 @@ typedef enum {
CMARK_NODE_INDENTED_CODE,
CMARK_NODE_HTML,
CMARK_NODE_PARAGRAPH,
- CMARK_NODE_HEADER,
+ CMARK_NODE_ATX_HEADER,
+ CMARK_NODE_SETEXT_HEADER,
CMARK_NODE_HRULE,
CMARK_NODE_REFERENCE_DEF,
@@ -203,7 +204,8 @@ 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_HEADER CMARK_NODE_HEADER
+ #define NODE_ATX_HEADER CMARK_NODE_ATX_HEADER
+ #define NODE_SETEXT_HEADER CMARK_NODE_SETEXT_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 e6971f8..0ce4443 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -149,7 +149,8 @@ static void node_to_html(strbuf *html, cmark_node *node)
break;
}
- case NODE_HEADER:
+ case NODE_ATX_HEADER:
+ case NODE_SETEXT_HEADER:
cr(html);
start_header[2] = '0' + cur->as.header.level;
strbuf_puts(html, start_header);
@@ -315,7 +316,8 @@ finish_node(strbuf *html, cmark_node *node, bool tight)
break;
}
- case NODE_HEADER:
+ case NODE_ATX_HEADER:
+ case NODE_SETEXT_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 3e51fec..35e19d2 100644
--- a/src/node.c
+++ b/src/node.c
@@ -13,7 +13,8 @@ cmark_node_new(cmark_node_type type) {
node->type = type;
switch (node->type) {
- case CMARK_NODE_HEADER:
+ case CMARK_NODE_ATX_HEADER:
+ case CMARK_NODE_SETEXT_HEADER:
node->as.header.level = 1;
break;
@@ -57,7 +58,8 @@ 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_HEADER: return "HEADER";
+ case CMARK_NODE_ATX_HEADER: return "ATX_HEADER";
+ case CMARK_NODE_SETEXT_HEADER: return "SETEXT_HEADER";
case CMARK_NODE_HRULE: return "HRULE";
case CMARK_NODE_REFERENCE_DEF: return "REFERENCE_DEF";
case CMARK_NODE_STRING: return "STRING";
@@ -157,7 +159,8 @@ 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_HEADER:
+ case CMARK_NODE_ATX_HEADER:
+ case CMARK_NODE_SETEXT_HEADER:
return node->as.header.level;
default:
@@ -174,7 +177,8 @@ cmark_node_set_header_level(cmark_node *node, int level) {
}
switch (node->type) {
- case CMARK_NODE_HEADER:
+ case CMARK_NODE_ATX_HEADER:
+ case CMARK_NODE_SETEXT_HEADER:
node->as.header.level = level;
return 1;
@@ -389,7 +393,8 @@ S_can_contain(cmark_node *node, cmark_node *child)
return child->type == CMARK_NODE_LIST_ITEM;
case CMARK_NODE_PARAGRAPH:
- case CMARK_NODE_HEADER:
+ case CMARK_NODE_ATX_HEADER:
+ case CMARK_NODE_SETEXT_HEADER:
case CMARK_NODE_EMPH:
case CMARK_NODE_STRONG:
case CMARK_NODE_LINK:
diff --git a/src/print.c b/src/print.c
index 2064276..b1bab4b 100644
--- a/src/print.c
+++ b/src/print.c
@@ -132,7 +132,11 @@ static void print_blocks(cmark_node* b, int indent)
}
print_blocks(b->first_child, indent + 2);
break;
- case NODE_HEADER:
+ 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:
printf("setext_header (level=%d)\n", b->as.header.level);
print_inlines(b->first_child, indent + 2);
break;