ignore mdpress format attributes, closes #88
[smdp.git] / src / parser.c
index 59b6b52..362a908 100644 (file)
@@ -2,7 +2,7 @@
  * Functions necessary to parse a file and transform its content into
  * a deck of slides containing lines. All based on markdown formating
  * rules.
- * Copyright (C) 2014 Michael Goehler
+ * Copyright (C) 2015 Michael Goehler
  *
  * This file is part of mdp.
  *
@@ -68,6 +68,14 @@ deck_t *markdown_load(FILE *input) {
                 // clear text
                 (text->reset)(text);
 
+            } else if(line && CHECK_BIT(bits, IS_STOP)) {
+
+                // set stop bit on last line
+                SET_BIT(line->bits, IS_STOP);
+
+                // clear text
+                (text->reset)(text);
+
             // if text is markdown hr
             } else if(CHECK_BIT(bits, IS_HR) &&
                       CHECK_BIT(line->bits, IS_EMPTY)) {
@@ -183,6 +191,30 @@ deck_t *markdown_load(FILE *input) {
     slide = deck->slide;
     while(slide) {
         line = slide->line;
+
+        // ignore mdpress format attributes
+        if(line &&
+           slide->lines > 1 &&
+           !CHECK_BIT(line->bits, IS_EMPTY) &&
+           line->text->value[line->offset] == L'=' &&
+           line->text->value[line->offset + 1] == L' ') {
+
+            // remove line from linked list
+            slide->line = line->next;
+            line->next->prev = NULL;
+
+            // maintain loop condition
+            tmp = line;
+            line = line->next;
+
+            // adjust line count
+            slide->lines -= 1;
+
+            // delete line
+            (tmp->text->delete)(tmp->text);
+            free(tmp);
+        }
+
         while(line) {
             // combine underlined H1/H2 in single line
             if((CHECK_BIT(line->bits, IS_H1) ||
@@ -308,6 +340,15 @@ int markdown_analyse(cstring_t *text, int prev) {
     // count leading spaces
     offset = next_nonblank(text, 0);
 
+    // IS_STOP
+    if((offset < CODE_INDENT || !CHECK_BIT(prev, IS_CODE)) &&
+       (!wcsncmp(&text->value[offset], L"<br>", 4) ||
+        !wcsncmp(&text->value[offset], L"<BR>", 4) ||
+        !wcsncmp(&text->value[offset], L"^", 1))) {
+        SET_BIT(bits, IS_STOP);
+        return bits;
+    }
+
     // strip trailing spaces
     for(eol = text->size; eol > offset && iswspace(text->value[eol - 1]); eol--);
 
@@ -381,7 +422,8 @@ int markdown_analyse(cstring_t *text, int prev) {
         // IS_CODE
         if(offset >= CODE_INDENT &&
            (CHECK_BIT(prev, IS_EMPTY) ||
-            CHECK_BIT(prev, IS_CODE))) {
+            CHECK_BIT(prev, IS_CODE)  ||
+            CHECK_BIT(prev, IS_STOP))) {
             SET_BIT(bits, IS_CODE);
 
         } else {