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);
+ }
}
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+package eu.svjatoslav.sixth.core.document;
+
+public class MdGenerator {
+}
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));
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);