summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commonmark.c15
-rw-r--r--src/latex.c9
-rw-r--r--src/render.c16
-rw-r--r--src/render.h7
4 files changed, 27 insertions, 20 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index 09644a0..7dc2767 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -163,8 +163,10 @@ get_containing_block(cmark_node *node)
}
static int
-S_render_node(cmark_node *node, cmark_event_type ev_type,
- cmark_renderer *renderer)
+S_render_node(cmark_renderer *renderer,
+ cmark_node *node,
+ cmark_event_type ev_type,
+ int options)
{
cmark_node *tmp;
int list_number;
@@ -337,14 +339,14 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
break;
case CMARK_NODE_LINEBREAK:
- if (!(CMARK_OPT_HARDBREAKS & renderer->options)) {
+ if (!(CMARK_OPT_HARDBREAKS & options)) {
LIT("\\");
}
CR();
break;
case CMARK_NODE_SOFTBREAK:
- if (renderer->width == 0) {
+ if (CMARK_OPT_HARDBREAKS & options) {
CR();
} else {
OUT(" ", true, LITERAL);
@@ -455,5 +457,10 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
char *cmark_render_commonmark(cmark_node *root, int options, int width)
{
+ if (options & CMARK_OPT_HARDBREAKS) {
+ // disable breaking on width, since it has
+ // a different meaning with OPT_HARDBREAKS
+ width = 0;
+ }
return cmark_render(root, options, width, outc, S_render_node);
}
diff --git a/src/latex.c b/src/latex.c
index e7a74d7..4fd1199 100644
--- a/src/latex.c
+++ b/src/latex.c
@@ -258,8 +258,10 @@ S_get_enumlevel(cmark_node *node)
}
static int
-S_render_node(cmark_node *node, cmark_event_type ev_type,
- cmark_renderer *renderer)
+S_render_node(cmark_renderer *renderer,
+ cmark_node *node,
+ cmark_event_type ev_type,
+ int options)
{
int list_number;
char list_number_string[20];
@@ -269,6 +271,9 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
"vi", "vii", "viii", "ix", "x"
};
+ // avoid warning about unused parameter:
+ (void)(options);
+
switch (node->type) {
case CMARK_NODE_DOCUMENT:
break;
diff --git a/src/render.c b/src/render.c
index 3b4976d..fb49248 100644
--- a/src/render.c
+++ b/src/render.c
@@ -124,9 +124,10 @@ cmark_render(cmark_node *root,
cmark_escaping,
int32_t,
unsigned char),
- int (*render_node)(cmark_node *node,
- cmark_event_type ev_type,
- cmark_renderer *renderer))
+ int (*render_node)(cmark_renderer *renderer,
+ cmark_node *node,
+ cmark_event_type ev_type,
+ int options))
{
cmark_strbuf pref = GH_BUF_INIT;
cmark_strbuf buf = GH_BUF_INIT;
@@ -135,18 +136,13 @@ cmark_render(cmark_node *root,
char *result;
cmark_iter *iter = cmark_iter_new(root);
-
- if (CMARK_OPT_HARDBREAKS & options) {
- width = 0;
- }
-
- cmark_renderer renderer = { options, &buf, &pref, 0, width,
+ cmark_renderer renderer = { &buf, &pref, 0, width,
0, 0, true, false, false,
outc, S_cr, S_blankline, S_out };
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
cur = cmark_iter_get_node(iter);
- if (!render_node(cur, ev_type, &renderer)) {
+ if (!render_node(&renderer, cur, ev_type, options)) {
// a false value causes us to skip processing
// the node's contents. this is used for
// autolinks.
diff --git a/src/render.h b/src/render.h
index 5f2a9ca..d050962 100644
--- a/src/render.h
+++ b/src/render.h
@@ -17,7 +17,6 @@ typedef enum {
} cmark_escaping;
struct cmark_renderer {
- int options;
cmark_strbuf* buffer;
cmark_strbuf* prefix;
int column;
@@ -49,10 +48,10 @@ cmark_render(cmark_node *root,
cmark_escaping,
int32_t,
unsigned char),
- int (*render_node)(cmark_node *node,
+ int (*render_node)(cmark_renderer *renderer,
+ cmark_node *node,
cmark_event_type ev_type,
- cmark_renderer *renderer));
-
+ int options));
#ifdef __cplusplus
}