From e6e265a23ae9e32b65ba6a70d302ae680e73138f Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 10 Aug 2020 21:30:01 +0300 Subject: [PATCH] Properly parse org headings --- .../sixth/core/document/Document.java | 21 ++++++++++++------- .../sixth/core/document/Heading.java | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) 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 e626304..262bee3 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Document.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Document.java @@ -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" diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java b/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java index fe335f5..23cc92f 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java @@ -100,7 +100,7 @@ public class Heading { } if (tm.isGroup(null)){ -// System.out.println(" HC: " + tm.token); + System.out.println("unhandled \"" + tm.token + "\""); continue; } -- 2.20.1