Properly parse org headings
[sixth.git] / src / main / java / eu / svjatoslav / sixth / core / document / Document.java
index e626304..262bee3 100644 (file)
@@ -1,5 +1,6 @@
 package eu.svjatoslav.sixth.core.document;
 
+import eu.svjatoslav.commons.string.String2;
 import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException;
 import eu.svjatoslav.commons.string.tokenizer.Tokenizer;
 import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch;
@@ -42,9 +43,13 @@ public class Document {
     }
 
     private void parseHeading(TokenizerMatch token) throws InvalidSyntaxException {
-        System.out.println("HEADING!! " + token.token);
-        int level = token.token.length()-1;
-//        createHeading(fromOrg(token.reminder), level);
+        // expected sample heading:
+        // ***** test heading
+
+        String[] headingSections = String2.getGroups(token.token, "(\\*+)[ \\t](.*)\\r?\\n");
+        int level = headingSections[0].length();
+        String title = headingSections[1];
+        createHeading(fromOrg(title), level);
     }
 
     public void parse(String fileContentsAsString) throws InvalidSyntaxException {
@@ -52,13 +57,15 @@ public class Document {
 
         // Org heading:
         // "*** Example Heading 1234"
-        tokenizer.addTerminator(PRESERVE, "\\*+\\s.*\\r?\\n", TG_HEADING);
+        tokenizer.addTerminator(PRESERVE, "\\*+[ \\t].*\\r?\\n", TG_HEADING);
 
         // Org list. Examples:
         // "   + my list title"
-        // "+"
-        tokenizer.addTerminator(PRESERVE, "\\s*(\\+|-)(\\s.*)?\\r?\\n", TG_LIST);
-        tokenizer.addTerminator(PRESERVE, "\\s+\\*(\\s.*)?\\r?\\n", TG_LIST);
+        // "   - my list title"
+        tokenizer.addTerminator(PRESERVE, "[ \\t]*(\\+|-)([ \\t].*)?\\r?\\n", TG_LIST);
+
+        // "   * my list title"
+        tokenizer.addTerminator(PRESERVE, "[ \\t]+\\*([ \\t].*)?\\r?\\n", TG_LIST);
 
         // DocumentProperty:
         // "#+OPTIONS: H:20 num:20"