summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-23 07:21:25 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-23 07:21:25 -0800
commitf7f010070d59bd2bd9334ef1f5f18e6d1631f9cc (patch)
tree85287f45145cf43f72c462edce4ef344b60ca6aa
parentf28197a69d56eb0f60d5931de58cbbfbb65ee794 (diff)
Added 'fenced' flag to cmark_code struct, renamed from cmark_fenced_code.
Technically we could do without this, since we can check for cmark_fence_length > 0. But it makes the code clearer and doesn't really increase the size of the node struct (because the size of the union is set by the data for lists).
-rw-r--r--src/blocks.c12
-rw-r--r--src/node.h5
2 files changed, 10 insertions, 7 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 7bf4d3d..5328638 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -194,7 +194,7 @@ static void finalize(cmark_doc_parser *parser, cmark_node* b, int line_number)
break;
case NODE_CODE_BLOCK:
- if (b->as.code.fence_length == 0) { // indented code
+ if (!b->as.code.fenced) { // indented code
remove_trailing_blank_lines(&b->string_content);
strbuf_putc(&b->string_content, '\n');
break;
@@ -539,7 +539,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
} else if (container->type == NODE_CODE_BLOCK) {
- if (container->as.code.fence_length == 0) { // indented
+ if (!container->as.code.fenced) { // indented
if (indent >= CODE_INDENT) {
offset += CODE_INDENT;
} else if (blank) {
@@ -608,6 +608,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
if (cur->type != NODE_PARAGRAPH && !blank) {
offset += CODE_INDENT;
container = add_child(parser, container, NODE_CODE_BLOCK, parser->line_number, offset + 1);
+ container->as.code.fenced = false;
container->as.code.fence_char = 0;
container->as.code.fence_length = 0;
container->as.code.fence_offset = 0;
@@ -642,6 +643,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
} else if ((matched = scan_open_code_fence(&input, first_nonspace))) {
container = add_child(parser, container, NODE_CODE_BLOCK, parser->line_number, first_nonspace + 1);
+ container->as.code.fenced = true;
container->as.code.fence_char = peek_at(&input, first_nonspace);
container->as.code.fence_length = matched;
container->as.code.fence_offset = first_nonspace - offset;
@@ -739,7 +741,7 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
container->type != NODE_BLOCK_QUOTE &&
container->type != NODE_HEADER &&
(container->type != NODE_CODE_BLOCK &&
- container->as.code.fence_length != 0) &&
+ container->as.code.fenced) &&
!(container->type == NODE_LIST_ITEM &&
container->first_child == NULL &&
container->start_line == parser->line_number));
@@ -768,12 +770,12 @@ void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
}
if (container->type == NODE_CODE_BLOCK &&
- container->as.code.fence_length == 0) {
+ !container->as.code.fenced) {
add_line(container, &input, offset);
} else if (container->type == NODE_CODE_BLOCK &&
- container->as.code.fence_length != 0) {
+ container->as.code.fenced) {
matched = 0;
if (indent <= 3 &&
diff --git a/src/node.h b/src/node.h
index 7bf6b2e..b842ed8 100644
--- a/src/node.h
+++ b/src/node.h
@@ -22,11 +22,12 @@ typedef struct {
} cmark_list;
typedef struct {
+ bool fenced;
int fence_length;
int fence_offset;
unsigned char fence_char;
cmark_strbuf info;
-} cmark_fenced_code;
+} cmark_code;
typedef struct {
int level;
@@ -58,7 +59,7 @@ struct cmark_node {
union {
cmark_chunk literal;
cmark_list list;
- cmark_fenced_code code;
+ cmark_code code;
cmark_header header;
cmark_link link;
} as;