From: NeilBrown Date: Sun, 5 May 2019 01:51:08 +0000 (+1000) Subject: mdcode: don't include blank lines at end of section. X-Git-Tag: JamisonCreek-3~26 X-Git-Url: https://ocean-lang.org/code/?a=commitdiff_plain;h=b757d6738f6ec0a1889e4f07dd49c1e1fd22092d;hp=9d5ec7afa939dcea026eb7a888ab7a92f509fd8c;p=ocean mdcode: don't include blank lines at end of section. completely blank lines (no indent) at the end of a section should not be considered part of that section, but rather separation between this and the next section. So don't include them in the code. When a section is used, for example, as sample output to test against actual output in a test suit, having the stray blank at the end can be problematic. Signed-off-by: NeilBrown --- diff --git a/csrc/mdcode.mdc b/csrc/mdcode.mdc index 8b9a8dc..8f53d18 100644 --- a/csrc/mdcode.mdc +++ b/csrc/mdcode.mdc @@ -541,7 +541,7 @@ There are two sorts of end markers: the presence of a particular string, or the absence of an indent. We will use a string to represent a presence, and a `NULL` to represent the absence. -While looking at code we don't think about paragraphs are all - just +While looking at code we don't think about paragraphs at all - just look for a line that starts with the right thing. Every line that is still code then needs to be examined to see if it is a section reference. @@ -557,6 +557,11 @@ number of spaces (counting 8 for tabs) after the natural indent of the code (which is a tab or 4 spaces). We use a separate function `count_spaces` for that. +If there are completely blank linkes (no indent) at the end of the found code, +these should be considered to be spacing between the code and the next section, +and so no included in the code. When a marker is used to explicitly mark the +end of the code, we don't need to check for these blank lines. + #### internal functions static int count_space(char *sol, char *p) @@ -633,6 +638,12 @@ for that. struct text txt; txt.txt = start; txt.len = pos - start; + /* strip trailing blank lines */ + while (!marker && txt.len > 2 && + start[txt.len-1] == '\n' && + start[txt.len-2] == '\n') + txt.len -= 1; + code_add_text(sect, txt, start_line, marker == NULL); }