diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2023-03-24 15:58:43 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-03-27 20:03:03 +0000 |
commit | f33e7bd06fdeeb8939dd49e76f69015db776846c (patch) | |
tree | a4796be2eeceaa5f93b90ea2f4e8a01468f69540 /sonar-markdown | |
parent | 78bd9b45b4f27a61eb04ec74fbb43db21b83fee6 (diff) | |
download | sonarqube-f33e7bd06fdeeb8939dd49e76f69015db776846c.tar.gz sonarqube-f33e7bd06fdeeb8939dd49e76f69015db776846c.zip |
SONAR-18895 fix markdown maximum heading level
Diffstat (limited to 'sonar-markdown')
-rw-r--r-- | sonar-markdown/src/main/java/org/sonar/markdown/HtmlHeadingChannel.java | 16 | ||||
-rw-r--r-- | sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java | 4 |
2 files changed, 11 insertions, 9 deletions
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlHeadingChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlHeadingChannel.java index 9e746bf66e6..8e9a5ea6c99 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlHeadingChannel.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlHeadingChannel.java @@ -58,15 +58,17 @@ public class HtmlHeadingChannel extends RegexChannel<MarkdownOutput> { 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()); diff --git a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java index 705888c838c..1476b589ac4 100644 --- a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java +++ b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownTest.java @@ -67,8 +67,8 @@ public class MarkdownTest { @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 |