summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-12-21 09:53:39 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2019-12-21 09:53:39 -0800
commit1880e6535e335f143f9547494def01c13f2f331b (patch)
tree2d16ce7260f99d7a3ef89781c38fba089bf30dad /src
parent77f7e7ae8b8f6c42c12e658c7a129429c1ba7bee (diff)
Commonmark renderer: always use fences for code (#317).
This solves problems with adjacent code blocks being merged.
Diffstat (limited to 'src')
-rw-r--r--src/commonmark.c54
1 files changed, 17 insertions, 37 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index f00d243..7438920 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -215,8 +215,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
break;
case CMARK_NODE_LIST:
- if (!entering && node->next && (node->next->type == CMARK_NODE_CODE_BLOCK ||
- node->next->type == CMARK_NODE_LIST)) {
+ if (!entering && node->next && (node->next->type == CMARK_NODE_LIST)) {
// this ensures that a following indented code block or list will be
// inteprereted correctly.
CR();
@@ -277,14 +276,6 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
break;
case CMARK_NODE_CODE_BLOCK:
- if (entering && node->prev &&
- (node->prev->type == CMARK_NODE_CODE_BLOCK)) {
- // this ensures that consecutive indented code blocks will not
- // be merged (#317)
- CR();
- LIT("<!-- end code block -->");
- BLANKLINE();
- }
first_in_list_item = node->prev == NULL && node->parent &&
node->parent->type == CMARK_NODE_ITEM;
@@ -297,34 +288,23 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
fencechar[0] = strchr(info, '`') == NULL ? '`' : '~';
code = cmark_node_get_literal(node);
code_len = strlen(code);
- // use indented form if no info, and code doesn't
- // begin or end with a blank line, and code isn't
- // first thing in a list item
- if (info_len == 0 && (code_len > 2 && !cmark_isspace(code[0]) &&
- !(cmark_isspace(code[code_len - 1]) &&
- cmark_isspace(code[code_len - 2]))) &&
- !first_in_list_item) {
- LIT(" ");
- cmark_strbuf_puts(renderer->prefix, " ");
- OUT(cmark_node_get_literal(node), false, LITERAL);
- cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 4);
- } else {
- numticks = longest_backtick_sequence(code) + 1;
- if (numticks < 3) {
- numticks = 3;
- }
- for (i = 0; i < numticks; i++) {
- LIT(fencechar);
- }
- LIT(" ");
- OUT(info, false, LITERAL);
- CR();
- OUT(cmark_node_get_literal(node), false, LITERAL);
- CR();
- for (i = 0; i < numticks; i++) {
- LIT(fencechar);
- }
+
+ numticks = longest_backtick_sequence(code) + 1;
+ if (numticks < 3) {
+ numticks = 3;
+ }
+ for (i = 0; i < numticks; i++) {
+ LIT(fencechar);
}
+ LIT(" ");
+ OUT(info, false, LITERAL);
+ CR();
+ OUT(cmark_node_get_literal(node), false, LITERAL);
+ CR();
+ for (i = 0; i < numticks; i++) {
+ LIT(fencechar);
+ }
+
BLANKLINE();
break;