Skip to content

Commit ecb6647

Browse files
committed
Consider code spans when escaping Markdown styling
Previously, Markdown styling, such as _ characters, in an issue title would always be escaped. This led to unnecessary escaping when the styling characters were used within a code span (text wrapped in backticks). This commit disables the escaping of Markdown styling for text within a code span. It does not consider the case where the code span uses multiple backticks as its opening and closing delimiters. Such usage in an issue title is considered to be unlikely and the added complexity of coping with such delimiters was not felt to be justified. Fixes gh-87
1 parent d76da27 commit ecb6647

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/java/io/spring/githubchangeloggenerator/ChangelogGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,17 @@ private static Escape htmlTags() {
258258

259259
private static Escape markdownStyling() {
260260
return (input) -> {
261+
boolean withinBackticks = false;
261262
char previous = ' ';
262263
StringBuilder result = new StringBuilder(input.length());
263264
for (char c : input.toCharArray()) {
264-
if (previous != '\\' && c == '*' || c == '_' || c == '~') {
265+
if (!withinBackticks && previous != '\\' && (c == '*' || c == '_' || c == '~')) {
265266
result.append('\\');
266267
}
267268
result.append(c);
269+
if (c == '`') {
270+
withinBackticks = !withinBackticks;
271+
}
268272
previous = c;
269273
}
270274
return result.toString();

src/test/java/io/spring/githubchangeloggenerator/ChangelogGeneratorTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,18 @@ void generateWhenMarkdownStylingIsInIssueTitleItIsEscaped() throws IOException {
295295
assertThat(new String(Files.readAllBytes(file))).contains("Bug 5 for \\~strikethrough\\~");
296296
}
297297

298+
@Test
299+
void generateWhenMarkdownStylingWithinBackTicksIsInIssueTitleItIsNotEscaped() throws IOException {
300+
setupGenerator(MilestoneReference.TITLE);
301+
List<Issue> issues = new ArrayList<>();
302+
issues.add(newIssue("Clarify `FactoryBean.OBJECT_TYPE_ATTRIBUTE` supported types", "1", "bug-1-url", Type.BUG));
303+
given(this.service.getMilestoneNumber("v2.3", REPO)).willReturn(23);
304+
given(this.service.getIssuesForMilestone(23, REPO)).willReturn(issues);
305+
Path file = generateChangelog("v2.3");
306+
assertThat(new String(Files.readAllBytes(file)))
307+
.contains("Clarify `FactoryBean.OBJECT_TYPE_ATTRIBUTE` supported types");
308+
}
309+
298310
@Test
299311
void generateWhenEscapedMarkdownStylingIsInIssueTitleItIsNotEscapedAgain() throws IOException {
300312
setupGenerator(MilestoneReference.TITLE);

0 commit comments

Comments
 (0)