Implement soft and hard line breaks.
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 66 67 68
diff --git a/README.md b/README.md
index c35b16e..8557d4b 100644
--- a/README.md
+++ b/README.md
@@ -105,8 +105,8 @@ more or less forms our to do list.
- [ ] 6.6 Images
- [ ] 6.7 Autolinks
- [ ] 6.8 Raw HTML
- - [ ] 6.9 Hard line breaks
- - [ ] 6.10 Soft line breaks
+ - [x] 6.9 Hard line breaks
+ - [x] 6.10 Soft line breaks
- [x] 6.11 Textual content
diff --git a/md2html/md2html.c b/md2html/md2html.c
index 0d3ac87..c062e2f 100644
--- a/md2html/md2html.c
+++ b/md2html/md2html.c
@@ -194,6 +194,8 @@ text_callback(MD_TEXTTYPE type, const MD_CHAR* text, MD_SIZE size, void* userdat
struct membuffer* out = (struct membuffer*) userdata;
switch(type) {
+ case MD_TEXT_BR: MEMBUF_APPEND_LITERAL(out, "<br>\n"); break;
+ case MD_TEXT_SOFTBR: MEMBUF_APPEND_LITERAL(out, "\n"); break;
case MD_TEXT_HTML: membuf_append(out, text, size); break;
default: membuf_append_escaped(out, text, size); break;
}
diff --git a/md4c/md4c.c b/md4c/md4c.c
index d2ee1f9..05f8775 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -289,7 +289,18 @@ md_process_normal_block(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
for(i = 0; i < n_lines; i++) {
MD_TEXT(MD_TEXT_NORMAL, STR(lines[i].beg), lines[i].end - lines[i].beg);
- MD_TEXT(MD_TEXT_NORMAL, _T("\n"), 1);
+
+ /* Output soft or hard line break. */
+ if(i + 1 < n_lines) {
+ MD_TEXTTYPE break_type;
+
+ if(CH(lines[i].end) == _T(' ') && CH(lines[i].end+1) == _T(' '))
+ break_type = MD_TEXT_BR;
+ else
+ break_type = MD_TEXT_SOFTBR;
+
+ MD_TEXT(break_type, _T("\n"), 1);
+ }
}
abort:
diff --git a/md4c/md4c.h b/md4c/md4c.h
index a8227cb..6948adb 100644
--- a/md4c/md4c.h
+++ b/md4c/md4c.h
@@ -95,6 +95,11 @@ enum MD_TEXTTYPE_tag {
/* Normal text. */
MD_TEXT_NORMAL = 0,
+ /* Line breaks.
+ * Note these are only sent within MD_BLOCK_CODE or MD_BLOCK_HTML. */
+ MD_TEXT_BR, /* <br> (hard break) */
+ MD_TEXT_SOFTBR, /* '\n' in source text where it is not semantically meaningful (soft break) */
+
/* Text in a code block (inside MD_BLOCK_CODE) or inlined code (`code`).
* If it is inside MD_BLOCK_CODE, it includes spaces for indentation and
* '\n' for new lines. MD_TEXT_BR and MD_TEXT_SOFTBR are not sent for this