Fix: By default, do not collapse whitespace.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
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.