From: Svjatoslav Agejenko Date: Thu, 30 Jul 2020 15:52:36 +0000 (+0300) Subject: Created document heading. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=4d6637215622edcf65ed246e0a63c9e7191e3fc3;p=sixth.git Created document heading. --- diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Document.java b/src/main/java/eu/svjatoslav/sixth/core/document/Document.java index 2c3d2f6..362265c 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Document.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Document.java @@ -1,4 +1,24 @@ package eu.svjatoslav.sixth.core.document; public class Document { + public final Heading rootHeading = new Heading("", 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("", 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 index 0000000..f9c3e6d --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java @@ -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 index 0000000..edc08f4 --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/core/document/MdGenerator.java @@ -0,0 +1,4 @@ +package eu.svjatoslav.sixth.core.document; + +public class MdGenerator { +} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java b/src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java index f420c48..15bd880 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java @@ -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);