protected void consume(CharSequence token, MarkdownOutput output) {
int index = 0;
int headingLevel = 0;
- while(index < token.length() && Character.isWhitespace(token.charAt(index))) {
- index ++;
+ while (index < token.length() && Character.isWhitespace(token.charAt(index))) {
+ index++;
}
- while(index < token.length() && index <= MAX_HEADING_DEPTH && token.charAt(index) == '=') {
- index ++;
- headingLevel ++;
+ while (index < token.length() && token.charAt(index) == '=') {
+ if (index < MAX_HEADING_DEPTH) {
+ headingLevel++;
+ }
+ index++;
}
- while(index < token.length() && Character.isWhitespace(token.charAt(index))) {
- index ++;
+ while (index < token.length() && Character.isWhitespace(token.charAt(index))) {
+ index++;
}
CharSequence headingText = token.subSequence(index, token.length());
@Test
public void shouldDecorateHeadings() {
- assertThat(Markdown.convertToHtml(" = Top\r== Sub\r\n=== Sub sub\n ==== \n 1.five"))
- .isEqualTo("<h1>Top</h1><h2>Sub</h2><h3>Sub sub</h3><h4></h4> 1.five");
+ assertThat(Markdown.convertToHtml(" = Top\r== Sub\r\n=== Sub sub\n ==== \n ===== five\n============ max"))
+ .isEqualTo("<h1>Top</h1><h2>Sub</h2><h3>Sub sub</h3><h4></h4><h5>five</h5><h6>max</h6>");
}
@Test