From ec64e9ea899c3f40e26aec8bfc4a9b8941b91cdf Mon Sep 17 00:00:00 2001 From: Pavlo Kapyshin Date: Fri, 18 Mar 2016 10:25:23 +0200 Subject: Add library option to render softbreaks as spaces --- api_test/main.c | 5 +++++ src/cmark.h | 4 ++++ src/html.c | 2 ++ 3 files changed, 11 insertions(+) diff --git a/api_test/main.c b/api_test/main.c index cd9ffb5..bde6222 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -788,6 +788,11 @@ static void line_endings(test_batch_runner *runner) { STR_EQ(runner, html, "

line
\nline

\n", "crlf endings with CMARK_OPT_HARDBREAKS"); free(html); + html = cmark_markdown_to_html(crlf_lines, sizeof(crlf_lines) - 1, + CMARK_OPT_DEFAULT | CMARK_OPT_NOBREAKS); + STR_EQ(runner, html, "

line line

\n", + "crlf endings with CMARK_OPT_NOBREAKS"); + free(html); static const char no_line_ending[] = "```\nline\n```"; html = cmark_markdown_to_html(no_line_ending, sizeof(no_line_ending) - 1, diff --git a/src/cmark.h b/src/cmark.h index 71c634b..7b7001e 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -519,6 +519,10 @@ char *cmark_render_latex(cmark_node *root, int options, int width); */ #define CMARK_OPT_SAFE (1 << 3) +/** Render `softbreak` elements as spaces. + */ +#define CMARK_OPT_NOBREAKS (1 << 4) + /** * ### Options affecting parsing */ diff --git a/src/html.c b/src/html.c index 9ffa08a..c2267cb 100644 --- a/src/html.c +++ b/src/html.c @@ -228,6 +228,8 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_SOFTBREAK: if (options & CMARK_OPT_HARDBREAKS) { cmark_strbuf_puts(html, "
\n"); + } else if (options & CMARK_OPT_NOBREAKS) { + cmark_strbuf_putc(html, ' '); } else { cmark_strbuf_putc(html, '\n'); } -- cgit v1.2.3 From bb7289750b93e20f760fb94fd04931b651e5ce3e Mon Sep 17 00:00:00 2001 From: Pavlo Kapyshin Date: Sun, 27 Mar 2016 15:01:03 +0300 Subject: Note that NOBREAKS option is HTML-only --- src/cmark.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmark.h b/src/cmark.h index 7b7001e..95ec623 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -519,7 +519,7 @@ char *cmark_render_latex(cmark_node *root, int options, int width); */ #define CMARK_OPT_SAFE (1 << 3) -/** Render `softbreak` elements as spaces. +/** Render `softbreak` elements as spaces (HTML only). */ #define CMARK_OPT_NOBREAKS (1 << 4) -- cgit v1.2.3