Created document heading.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 30 Jul 2020 15:52:36 +0000 (18:52 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 30 Jul 2020 15:52:36 +0000 (18:52 +0300)
src/main/java/eu/svjatoslav/sixth/core/document/Document.java
src/main/java/eu/svjatoslav/sixth/core/document/Heading.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/sixth/core/document/MdGenerator.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java

index 2c3d2f6..362265c 100644 (file)
@@ -1,4 +1,24 @@
 package eu.svjatoslav.sixth.core.document;
 
 public class Document {
+    public final Heading rootHeading = new Heading("<root>", 0, null);
+
+    private Heading currentHeading = rootHeading;
+
+    public Heading createHeading(String name, int targetLevel){
+        if (currentHeading.level == (targetLevel - 1)){
+            Heading newHeading = new Heading(name, targetLevel, currentHeading);
+            currentHeading = newHeading;
+            return newHeading;
+        }
+
+        if (currentHeading.level > (targetLevel - 1)){
+            currentHeading = currentHeading.parent;
+            return createHeading(name, targetLevel);
+        }
+
+        Heading missingIntermediate = new Heading("<noname>", currentHeading.level + 1, currentHeading);
+        currentHeading = missingIntermediate;
+        return createHeading(name, targetLevel);
+    }
 }
diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java b/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java
new file mode 100644 (file)
index 0000000..f9c3e6d
--- /dev/null
@@ -0,0 +1,14 @@
+package eu.svjatoslav.sixth.core.document;
+
+public class Heading {
+    public final String name;
+    public final int level;
+    public final Heading parent;
+
+    public Heading(String name, int level, Heading parent){
+        this.level = level;
+        this.name = name;
+        this.parent = parent;
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/MdGenerator.java b/src/main/java/eu/svjatoslav/sixth/core/document/MdGenerator.java
new file mode 100644 (file)
index 0000000..edc08f4
--- /dev/null
@@ -0,0 +1,4 @@
+package eu.svjatoslav.sixth.core.document;
+
+public class MdGenerator {
+}
index f420c48..15bd880 100644 (file)
@@ -14,8 +14,10 @@ import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrat
 
 public class OrgParser {
 
+    private Document document;
+
     public Document parse(File file) throws IOException, InvalidSyntaxException {
-        Document document = new Document();
+        document = new Document();
 
         Tokenizer lineTokenizer = getFileToLineTokenizer(getFileContentsAsString(file));
 
@@ -40,12 +42,15 @@ public class OrgParser {
             return;
 
         if (token.token.startsWith("*")){
-            System.out.println("LINE: " + line);
-            System.out.println(token);
-            System.out.println();
+            parseHeading(line, token);
+            return;
         }
     }
 
+    private void parseHeading(String line, TokenizerMatch token) {
+        int level = token.token.length()-1;
+        document.createHeading(token.reminder, level);
+   }
 
     private Tokenizer getLineTokenizer(String contents) {
         final Tokenizer tokenizer = new Tokenizer(contents);