Skip to content

Commit bd1c723

Browse files
committed
[asciidoc] Add support for hard line breaks (fix #30)
1 parent 95153ec commit bd1c723

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

asciidoc-java/src/main/java/io/yupiik/asciidoc/parser/Parser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ private List<Element> doParse(final Reader reader, final Predicate<String> conti
267267
}
268268
elements.add(new Quote(doParse(new Reader(buffer), l -> true, resolver, attributes, supportComplexStructures), options == null ? Map.of() : options));
269269
options = null;
270+
} else if (stripped.endsWith(" +")) {
271+
elements.addAll(parseLine(reader, stripped.substring(0, stripped.length()-2), resolver, attributes, supportComplexStructures));
272+
elements.add(new LineBreak());
273+
options = null;
270274
} else if (stripped.startsWith(":") && (attributeMatcher = ATTRIBUTE_DEFINITION.matcher(stripped)).matches()) {
271275
final var value = attributeMatcher.groupCount() == 3 ? ofNullable(attributeMatcher.group("value")).orElse("") : "";
272276
final var name = attributeMatcher.group("name");

asciidoc-java/src/test/java/io/yupiik/asciidoc/parser/ParserTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.yupiik.asciidoc.model.ConditionalBlock;
2525
import io.yupiik.asciidoc.model.DescriptionList;
2626
import io.yupiik.asciidoc.model.Element;
27+
import io.yupiik.asciidoc.model.LineBreak;
2728
import io.yupiik.asciidoc.model.Link;
2829
import io.yupiik.asciidoc.model.Macro;
2930
import io.yupiik.asciidoc.model.OpenBlock;
@@ -1263,4 +1264,19 @@ void icon() {
12631264
List.of(new Macro("icon", "heart", Map.of("size", "2x"), true)),
12641265
new Parser().parseBody(new Reader(List.of("icon:heart[size=2x]")), null).children());
12651266
}
1267+
1268+
@Test
1269+
void hardbreak() {
1270+
final var body = new Parser().parseBody(new Reader(List.of("""
1271+
Rubies are red, +
1272+
Topazes are blue.
1273+
""".split("\n"))), null);
1274+
assertEquals(
1275+
List.of(new Text(List.of(), "Rubies are red,", Map.of()),
1276+
new LineBreak(),
1277+
new Text(List.of(), "Topazes are blue.", Map.of())),
1278+
body.children());
1279+
}
1280+
1281+
12661282
}

0 commit comments

Comments
 (0)