Skip to content

Commit b86fb11

Browse files
committed
Refine formatter comp regex
Update the regex to completely remove the formatter comment line. Closes gh-21
1 parent ddc0f2a commit b86fb11

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/main/java/io/spring/asciidoctor/backend/codetools/ChompListingContentConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private String chompFilePatterns(String content) {
167167

168168
private static class FormatterChomper implements Chomper {
169169

170-
private static final Pattern PATTERN = Pattern.compile("^\\s*\\/\\/\\s*@formatter:(on|off).*\n?$",
170+
private static final Pattern PATTERN = Pattern.compile("^[\\ \\t]*\\/\\/\\s*@formatter:(on|off).*$\n?",
171171
Pattern.MULTILINE);
172172

173173
@Override

src/test/java/io/spring/asciidoctor/backend/codetools/ChompListingContentConverterTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void convertWhenFormattersChompReturnsChompedLines(ConvertedHtml html) {
8787
assertThat(html.getElementHtml("code")).isEqualTo("public class Example {}");
8888
}
8989

90+
@Test
91+
void convertWhenMethodFormattersChompReturnsChompedLines(ConvertedHtml html, ExpectedHtml expected) {
92+
assertThat(html.getElementHtml("code")).satisfies(expected);
93+
}
94+
9095
@Test
9196
void convertWhenMultipleChompsReturnsChompedLines(ConvertedHtml html, ExpectedHtml expected) {
9297
assertThat(html.getElementHtml("code")).satisfies(expected);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
= Test Document
2+
:chomp: formatters
3+
4+
[source,java]
5+
----
6+
public class Example {
7+
8+
public void method() {
9+
// @formatter:off
10+
new StringBuilder();
11+
// @formatter:on
12+
}
13+
14+
}
15+
----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class Example {
2+
3+
public void method() {
4+
new StringBuilder();
5+
}
6+
7+
}

0 commit comments

Comments
 (0)