Skip to content

Commit fd33435

Browse files
committed
Fix line break parsing after hard line break
Fixes #415.
1 parent 0418c83 commit fd33435

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html),
77
with the exception that 0.x versions can break between minor versions.
88

9+
## [Unreleased]
10+
### Fixed
11+
- Line(s) after a hard line break would sometimes also get an unwanted hard
12+
line break, e.g. if they ended in emphasis or other non-text inlines (#415)
13+
914
## [0.27.0] - 2025-10-12
1015
### Added
1116
- Autolink extension: Now supports configuration of different link types that
@@ -510,6 +515,7 @@ API breaking changes (caused by changes in spec):
510515
Initial release of commonmark-java, a port of commonmark.js with extensions
511516
for autolinking URLs, GitHub flavored strikethrough and tables.
512517
518+
[Unreleased]: https://github.com/commonmark/commonmark-java/compare/commonmark-parent-0.27.0...main
513519
[0.27.0]: https://github.com/commonmark/commonmark-java/compare/commonmark-parent-0.26.0...commonmark-parent-0.27.0
514520
[0.26.0]: https://github.com/commonmark/commonmark-java/compare/commonmark-parent-0.25.1...commonmark-parent-0.26.0
515521
[0.25.1]: https://github.com/commonmark/commonmark-java/compare/commonmark-parent-0.25.0...commonmark-parent-0.25.1

commonmark/src/main/java/org/commonmark/internal/InlineParserImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,9 @@ static String parseLinkLabel(Scanner scanner) {
598598
private Node parseLineBreak() {
599599
scanner.next();
600600

601-
if (trailingSpaces >= 2) {
601+
var hard = trailingSpaces >= 2;
602+
trailingSpaces = 0;
603+
if (hard) {
602604
return new HardLineBreak();
603605
} else {
604606
return new SoftLineBreak();

commonmark/src/test/java/org/commonmark/test/CoreRenderingTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class CoreRenderingTestCase extends RenderingTestCase {
1111

1212
@Override
1313
protected String render(String source) {
14-
return RENDERER.render(PARSER.parse(source));
14+
var node = PARSER.parse(source);
15+
return RENDERER.render(node);
1516
}
1617
}

commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,19 @@ public void htmlBlockInterruptingList() {
210210
"</ul>\n" +
211211
"</script>\n");
212212
}
213+
214+
@Test
215+
public void emphasisAfterHardLineBreak() {
216+
assertRendering("Hello \n" +
217+
"**Bar**\n" +
218+
"Foo\n", "<p>Hello<br />\n" +
219+
"<strong>Bar</strong>\n" +
220+
"Foo</p>\n");
221+
222+
assertRendering("Hello \n" +
223+
"**Bar** \n" +
224+
"Foo\n", "<p>Hello<br />\n" +
225+
"<strong>Bar</strong><br />\n" +
226+
"Foo</p>\n");
227+
}
213228
}

0 commit comments

Comments
 (0)