Properly parse org headings
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 10 Aug 2020 18:30:01 +0000 (21:30 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 10 Aug 2020 18:30:01 +0000 (21:30 +0300)
src/main/java/eu/svjatoslav/sixth/core/document/Document.java
src/main/java/eu/svjatoslav/sixth/core/document/Heading.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"
index fe335f5..23cc92f 100644 (file)
@@ -100,7 +100,7 @@ public class Heading {
             }
 
             if (tm.isGroup(null)){
-//                System.out.println("    HC: " + tm.token);
+                System.out.println("unhandled \"" + tm.token + "\"");
                 continue;
             }