diff --git a/redpen-core/src/main/java/cc/redpen/parser/review/ReVIEWParser.java b/redpen-core/src/main/java/cc/redpen/parser/review/ReVIEWParser.java index 9d491d88e..e1cc6b781 100644 --- a/redpen-core/src/main/java/cc/redpen/parser/review/ReVIEWParser.java +++ b/redpen-core/src/main/java/cc/redpen/parser/review/ReVIEWParser.java @@ -168,16 +168,23 @@ private void processLine(Line line, Model model, State state) { while (line.charAt(headerIndent) == '=') { headerIndent++; } - if (line.charAt(headerIndent) == '[') { // column? - while (line.charAt(headerIndent) != ']' - && line.charAt(headerIndent) != 0) { - headerIndent++; + int cursor = headerIndent; + if (line.charAt(cursor) == '[') { // column? + while (line.charAt(cursor) != ']' + && line.charAt(cursor) != 0) { + cursor++; } - headerIndent++; + cursor++; + } else if (line.charAt(cursor) == '{') { // label? + while (line.charAt(cursor) != '}' + && line.charAt(cursor) != 0) { + cursor++; + } + cursor++; } - if ((headerIndent > 0) && (line.charAt(headerIndent) == ' ')) { - line.erase(0, headerIndent + 1); - line.setSectionLevel(headerIndent); + if ((cursor > 0) && (line.charAt(cursor) == ' ')) { + line.erase(0, cursor + 1); + line.setSectionLevel(cursor); } if (target.line.startsWith("===[/column]")) { // closing.. line.erase(); diff --git a/redpen-core/src/test/java/cc/redpen/parser/review/ReVIEWParserTest.java b/redpen-core/src/test/java/cc/redpen/parser/review/ReVIEWParserTest.java index a3b1278d5..57f501e1a 100644 --- a/redpen-core/src/test/java/cc/redpen/parser/review/ReVIEWParserTest.java +++ b/redpen-core/src/test/java/cc/redpen/parser/review/ReVIEWParserTest.java @@ -205,6 +205,24 @@ void testSectionHeader() throws UnsupportedEncodingException { assertEquals("About Gekioko.", doc.getSection(0).getHeaderContent(0).getContent()); } + @Test + void testLabelledSectionHeader() throws UnsupportedEncodingException { + String sampleText = "={About} About @{Gekioko}.\n\n" + + "Gekioko means angry."; + + Document doc = createFileContent(sampleText); + assertEquals(1, doc.size()); + assertEquals("About Gekioko.", doc.getSection(0).getHeaderContent(0).getContent()); + } + + @Test + void testInvalidLabelledSectionHeader() throws UnsupportedEncodingException { + String sampleText = "={About"; // NOTE: no "}" + Document doc = createFileContent(sampleText); + assertEquals(1, doc.size()); + assertEquals("={About", doc.getSection(0).getParagraph(0).getSentence(0).getContent()); + } + @Test void testColumnSectionHeader() throws UnsupportedEncodingException { String sampleText = "==[column] About Gekioko. \n\n"; @@ -221,6 +239,18 @@ void testInvalidColumnSectionHeader() throws UnsupportedEncodingException { assertEquals("==[column About Gekioko.", doc.getSection(0).getParagraph(0).getSentence(0).getContent()); } + @Test + void testDocSize() throws UnsupportedEncodingException { + String sampleText = "= Without Label\n" + + "=={WithLabel} With Label\n" + + "==={WithLabel} With Label\n\n" + + "={WithLabel} With Label\n" + + "==[column] Column"; + + Document doc = createFileContent(sampleText); + assertEquals(5, doc.size()); + } + @Test void testDocumentWithBoldWord() { String sampleText = "It is a @{good} day.";