summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-03-21 20:40:41 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-03-21 20:40:41 -0700
commit6c0da96b490f0889282d20ce5c30ec18e351f1c1 (patch)
tree3dce927175748161406bf771bc0d23587e8ac9f2 /src
parent393c9507b033e3115c57887e8863f40d45f1a999 (diff)
CommonMark renderer: improved code blocks.
* Use indented code block if no info. * Print info string on fenced blocks.
Diffstat (limited to 'src')
-rw-r--r--src/commonmark.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index 73c3d2d..c51be5c 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -161,6 +161,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
cmark_node *tmp;
int list_number;
bool entering = (ev_type == CMARK_EVENT_ENTER);
+ const char *info;
switch (node->type) {
case CMARK_NODE_DOCUMENT:
@@ -221,14 +222,23 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
case CMARK_NODE_CODE_BLOCK:
blankline(state);
- // TODO variable number of ticks
- lit(state, "```", false);
- cr(state);
- // TODO info string
- // TODO use indented form if no info string?
- out(state, node->as.code.literal, false, true);
- cr(state);
- lit(state, "```", false);
+ // TODO variable number of ticks, depending on contents
+ info = cmark_node_get_fence_info(node);
+ if (info == NULL || strlen(info) == 0) {
+ // use indented form if no info
+ lit(state, " ", false);
+ cmark_strbuf_puts(state->prefix, " ");
+ out(state, node->as.code.literal, false, false);
+ cmark_strbuf_truncate(state->prefix,
+ state->prefix->size - 4);
+ } else {
+ lit(state, "``` ", false);
+ out(state, cmark_chunk_literal(info), false, false);
+ cr(state);
+ out(state, node->as.code.literal, false, true);
+ cr(state);
+ lit(state, "```", false);
+ }
blankline(state);
break;