Skip to content

Commit

Permalink
Merge pull request #844 from tokorom/support-labelled-section-in-review
Browse files Browse the repository at this point in the history
Support labelled section in Re:VIEW
  • Loading branch information
takahi-i authored Sep 5, 2018
2 parents 7d0c0c3 + 4fe7ef8 commit 54250aa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 @<i>{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";
Expand All @@ -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 @<b>{good} day.";
Expand Down

0 comments on commit 54250aa

Please sign in to comment.