Fix: Strip blank lines at start and end of indented code block.
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
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 8691b0e..f46229f 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -1162,6 +1162,26 @@ abort:
return ret;
}
+static int
+md_process_code_block(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
+{
+ /* Ignore blank lines at start/end of indented code block. */
+ if(lines[0].type == MD_LINE_INDENTEDCODE) {
+ while(n_lines > 0 && lines[0].beg == lines[0].end) {
+ lines++;
+ n_lines--;
+ }
+ while(n_lines > 0 && lines[n_lines-1].beg == lines[n_lines-1].end) {
+ n_lines--;
+ }
+
+ if(n_lines == 0)
+ return 0;
+ }
+
+ return md_process_verbatim_block(ctx, MD_TEXT_CODE, lines, n_lines);
+}
+
/***************************************
*** Breaking Document into Blocks ***
@@ -1749,7 +1769,7 @@ md_process_block(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
break;
case MD_BLOCK_CODE:
- ret = md_process_verbatim_block(ctx, MD_TEXT_CODE, lines, n_lines);
+ ret = md_process_code_block(ctx, lines, n_lines);
break;
case MD_BLOCK_HTML: