commit dac9acdb46e20c793bacca3e5c137f96ef1e9488
parent fa112a283547e9688c7b4e20e0de155555bd17b8
Author: Martin Mitas <mity@morous.org>
Date: Sat, 8 Oct 2016 22:21:01 +0200
Fix: Strip blank lines at start and end of indented code block.
Diffstat:
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git 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: