summaryrefslogtreecommitdiff
path: root/src/commonmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/commonmark.c')
-rw-r--r--src/commonmark.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index 95a1ae5..0db0f34 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -167,9 +167,11 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
int list_number;
cmark_delim_type list_delim;
int numticks;
+ bool extra_spaces;
int i;
bool entering = (ev_type == CMARK_EVENT_ENTER);
const char *info, *code, *title;
+ char fencechar[2] = {'\0', '\0'};
size_t info_len, code_len;
char listmarker[LISTMARKER_SIZE];
char *emph_delim;
@@ -277,6 +279,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
}
info = cmark_node_get_fence_info(node);
info_len = strlen(info);
+ 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
@@ -296,7 +299,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
numticks = 3;
}
for (i = 0; i < numticks; i++) {
- LIT("`");
+ LIT(fencechar);
}
LIT(" ");
OUT(info, false, LITERAL);
@@ -304,7 +307,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
OUT(cmark_node_get_literal(node), false, LITERAL);
CR();
for (i = 0; i < numticks; i++) {
- LIT("`");
+ LIT(fencechar);
}
}
BLANKLINE();
@@ -363,14 +366,17 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
code = cmark_node_get_literal(node);
code_len = strlen(code);
numticks = shortest_unused_backtick_sequence(code);
+ extra_spaces = code_len == 0 ||
+ code[0] == '`' || code[code_len - 1] == '`' ||
+ code[0] == ' ' || code[code_len - 1] == ' ';
for (i = 0; i < numticks; i++) {
LIT("`");
}
- if (code_len == 0 || code[0] == '`') {
+ if (extra_spaces) {
LIT(" ");
}
OUT(cmark_node_get_literal(node), allow_wrap, LITERAL);
- if (code_len == 0 || code[code_len - 1] == '`') {
+ if (extra_spaces) {
LIT(" ");
}
for (i = 0; i < numticks; i++) {