Commit de2338ece88ef2bb1a890b00d2592255ca880732

Martin Mitas 2016-10-09T00:42:30

Fix: By default, do not collapse whitespace.

diff --git a/md2html/md2html.c b/md2html/md2html.c
index 854802f..f58fd76 100644
--- a/md2html/md2html.c
+++ b/md2html/md2html.c
@@ -424,6 +424,7 @@ static const option cmdline_options[] = {
     { "fpermissive-atx-headers",     0,  'A', OPTION_ARG_NONE },
     { "fno-indented-code",           0,  'I', OPTION_ARG_NONE },
     { "fno-html-blocks",             0,  'H', OPTION_ARG_NONE },
+    { "fcollapse-whitespace",        0,  'W', OPTION_ARG_NONE },
     { 0 }
 };
 
@@ -441,6 +442,7 @@ usage(void)
         "  -h, --help               display this help and exit\n"
         "\n"
         "Markdown dialect options:\n"
+        "      --fcollapse-whitespace       collapse non-trivial whitespace\n"
         "      --fverbatim-entities         do not translate entities\n"
         "      --fpermissive-atx-headers    allow ATX headers without delimiting space\n"
         "      --fno-indented-code          disable indented code blocks\n"
@@ -473,6 +475,7 @@ cmdline_callback(int opt, char const* value, void* data)
         case 'A':   renderer_flags |= MD_FLAG_PERMISSIVEATXHEADERS; break;
         case 'I':   renderer_flags |= MD_FLAG_NOINDENTEDCODEBLOCKS; break;
         case 'H':   renderer_flags |= MD_FLAG_NOHTMLBLOCKS; break;
+        case 'W':   renderer_flags |= MD_FLAG_COLLAPSEWHITESPACE; break;
 
         default:
             fprintf(stderr, "Illegal option: %s\n", value);
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 4cfcd4a..8daccef 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -702,7 +702,7 @@ md_collect_marks(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
             }
 
             /* Turn non-trivial whitespace into single space. */
-            if(ISWHITESPACE_(ch)) {
+            if(ISWHITESPACE_(ch)  &&  (ctx->r.flags & MD_FLAG_COLLAPSEWHITESPACE)) {
                 OFF tmp = off+1;
 
                 while(tmp < end  &&  ISWHITESPACE(tmp))
diff --git a/md4c/md4c.h b/md4c/md4c.h
index 929a9ee..2b86368 100644
--- a/md4c/md4c.h
+++ b/md4c/md4c.h
@@ -147,13 +147,14 @@ struct MD_BLOCK_CODE_DETAIL_tag {
 
 /* Flags specifying Markdown dialect.
  *
- * By default (when MD_RENDERER::flags == 0), we follow CommMark specification.
+ * By default (when MD_RENDERER::flags == 0), we follow CommonMark specification.
  * The following flags may allow some extensions or deviations from it.
  */
-#define MD_FLAG_PERMISSIVEATXHEADERS    0x0001  /* Do not require space in ATX headers ( ###header ) */
-#define MD_FLAG_NOINDENTEDCODEBLOCKS    0x0002  /* Disable indented code blocks. (Only fenced code works.) */
-#define MD_FLAG_NOHTMLBLOCKS            0x0004  /* Disable raw HTML blocks. */
-#define MD_FLAG_NOHTMLSPANS             0x0008  /* Disable raw HTML (inline). */
+#define MD_FLAG_COLLAPSEWHITESPACE      0x0001  /* In MD_TEXT_NORMAL, collapse non-trivial whitespace into single ' ' */
+#define MD_FLAG_PERMISSIVEATXHEADERS    0x0002  /* Do not require space in ATX headers ( ###header ) */
+#define MD_FLAG_NOINDENTEDCODEBLOCKS    0x0004  /* Disable indented code blocks. (Only fenced code works.) */
+#define MD_FLAG_NOHTMLBLOCKS            0x0010  /* Disable raw HTML blocks. */
+#define MD_FLAG_NOHTMLSPANS             0x0020  /* Disable raw HTML (inline). */
 #define MD_FLAG_NOHTML                  (MD_FLAG_NOHTMLBLOCKS | MD_FLAG_NOHTMLSPANS)
 
 /* Caller-provided callbacks.