]> ocean-lang.org Git - ocean/blobdiff - csrc/mdcode.mdc
oceani: simplify test in var_block_close.
[ocean] / csrc / mdcode.mdc
index 8f53d184b21010c3fe6ab64c08146c129919588d..cf6887dea25c316bab6bc6679ce2f8e2d622a046 100644 (file)
@@ -119,7 +119,6 @@ will "do the right thing".
        libmdcode.o : libmdcode.c mdcode.h
                $(CC) $(CFLAGS) -c libmdcode.c
 
-
 ### File: md2c.c
 
        #include <unistd.h>
@@ -162,8 +161,11 @@ the root.
 
 Finally we need to know if the `code_node` was recognised by being
 indented or not.  If it was, the client of this data will want to
-strip of the leading tab or 4 spaces.  Hence a `needs_strip` flag is
-needed.
+strip off the leading tab or 4 spaces.  Hence a `needs_strip` flag is
+needed.  This will be set to 8 if a tab is found and 4 if four spaces are found.
+This means the relative indent of text in the node
+is `node->indent - node->needs_strip`.
+The relative indent is needed for detecting indents in the overall file.
 
 ##### exported types
 
@@ -288,7 +290,13 @@ in a new node.
                n->code = txt;
                n->indent = 0;
                n->line_no = line_no;
-               n->needs_strip = needs_strip;
+               if (needs_strip) {
+                       if (txt.txt[0] == '\t')
+                               n->needs_strip = 8;
+                       else
+                               n->needs_strip = 4;
+               } else
+                       n->needs_strip = 0;
                n->next = NULL;
                n->child = NULL;
                if (where->last)
@@ -577,7 +585,6 @@ end of the code, we don't need to check for these blank lines.
                return c;
        }
 
-
        static char *take_code(char *pos, char *end, char *marker,
                               struct psection **table, struct text section,
                               int *line_nop)
@@ -774,7 +781,6 @@ error message - a `code_err_fn`.
 
        struct section *code_extract(char *pos, char *end, code_err_fn error);
 
-
 ## Using the library
 
 Now that we can extract code from a document and link it all together
@@ -800,8 +806,8 @@ This could go wrong if the first line of a code block marked by
 _`` ``` ``_ is indented.  To overcome this we would need to
 record some extra state in each `code_node`.  For now we won't bother.
 
-The indents we insert will all be spaces.  This might not work well
-for `Makefiles`.
+The indents we insert will mostly be spaces.  All-spaces doesn't work
+for `Makefiles`, so if the indent is 8 or more, we use a TAB first.
 
 ##### internal functions
 
@@ -818,7 +824,10 @@ for `Makefiles`.
                        fprintf(out, "#line %d \"%s\"\n",
                                node->line_no, fname);
                        while (len && *c) {
-                               fprintf(out, "%*s", node->indent, "");
+                               if (node->indent >= 8)
+                                       fprintf(out, "\t%*s", node->indent - 8, "");
+                               else
+                                       fprintf(out, "%*s", node->indent, "");
                                if (node->needs_strip) {
                                        if (*c == '\t' && len > 1) {
                                                c++;
@@ -880,7 +889,6 @@ And now we take a single file name, extract the code, and if there are
 no error we write out a file for each appropriate code section.  And
 we are done.
 
-
 ##### client includes
 
        #include <fcntl.h>