]> ocean-lang.org Git - ocean/commitdiff
mdcode: don't include blank lines at end of section.
authorNeilBrown <neil@brown.name>
Sun, 5 May 2019 01:51:08 +0000 (11:51 +1000)
committerNeilBrown <neil@brown.name>
Sun, 5 May 2019 01:51:08 +0000 (11:51 +1000)
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 <neil@brown.name>
csrc/mdcode.mdc

index 8b9a8dcc8a02f1ae45fe9d9fb104e7d0140bff2b..8f53d184b21010c3fe6ab64c08146c129919588d 100644 (file)
@@ -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);
                }