cmark

My personal build of CMark ✏️

Commit
0b6805c0c544cfd8973f457142434127cac4b3a5
Parent
6e8c3f6148ec586fd4cc5c89c644422dd6ec33d5
Author
John MacFarlane <jgm@berkeley.edu>
Date

Merge pull request #111 from PavloKapyshin/master

Add library option to render softbreaks as spaces

Diffstat

3 files changed, 11 insertions, 0 deletions

Status File Name N° Changes Insertions Deletions
Modified api_test/main.c 5 5 0
Modified src/cmark.h 4 4 0
Modified src/html.c 2 2 0
diff --git a/api_test/main.c b/api_test/main.c
@@ -791,6 +791,11 @@ static void line_endings(test_batch_runner *runner) {
   STR_EQ(runner, html, "<p>line<br />\nline</p>\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, "<p>line line</p>\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
@@ -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 (HTML only).
+ */
+#define CMARK_OPT_NOBREAKS (1 << 4)
+
 /**
  * ### Options affecting parsing
  */
diff --git 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, "<br />\n");
+    } else if (options & CMARK_OPT_NOBREAKS) {
+      cmark_strbuf_putc(html, ' ');
     } else {
       cmark_strbuf_putc(html, '\n');
     }