Skip to content

Commit

Permalink
[asciidoc] more tolerance in indented lists
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Feb 12, 2024
1 parent 7e9be16 commit a3c20f9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1137,17 +1137,18 @@ private <T extends Element> T parseList(final Reader reader, final String option
final ContentResolver resolver, final Map<String, String> currentAttributes) {
final var children = new ArrayList<Element>(2);
String next;
String nextStripped;
final var buffer = new StringBuilder();
Matcher matcher;
final int currentLevel = prefix.length() - 1 /*ending space*/;
while ((next = reader.nextLine()) != null && (matcher = regex.matcher(next)).matches() && !next.isBlank()) {
while ((next = reader.nextLine()) != null && (matcher = regex.matcher((nextStripped=next.strip()))).matches() && !next.isBlank()) {
final var level = matcher.group(captureName).length();
if (level < currentLevel) { // go back to parent
break;
}
if (level == currentLevel) { // a new item
buffer.setLength(0);
buffer.append(next.substring(prefix.length()).stripLeading());
buffer.append(nextStripped.substring(prefix.length()).stripLeading());
while ((next = reader.nextLine()) != null) {
if (next.isBlank()) {
break;
Expand All @@ -1156,7 +1157,7 @@ private <T extends Element> T parseList(final Reader reader, final String option
buffer.append('\n');
continue;
}
if (regex.matcher(next).matches()) {
if (regex.matcher(next.strip()).matches()) {
break;
}
buffer.append('\n').append(next);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import io.yupiik.asciidoc.model.Table;
import io.yupiik.asciidoc.model.Text;
import io.yupiik.asciidoc.model.UnOrderedList;
import io.yupiik.asciidoc.parser.internal.LocalContextResolver;
import io.yupiik.asciidoc.parser.internal.Reader;
import io.yupiik.asciidoc.parser.resolver.ContentResolver;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -491,6 +490,31 @@ void unorderedList() {
body.children());
}

@Test
void unorderedListUnCommonFormatting() {
final var body = new Parser().parseBody(new Reader(List.of("""
* something:
Some description.
** Parameters:
*** --resolve-provider: ...
*** --resolve-relaxed: ...
""".split("\n"))), null);
assertEquals(List.of(
new UnOrderedList(
List.of(
new Paragraph(List.of(
new Text(List.of(), "something: Some description.", Map.of()),
new UnOrderedList(List.of(
new Paragraph(List.of(
new Text(List.of(), "Parameters:", Map.of()),
new UnOrderedList(List.of(
new Text(List.of(), "--resolve-provider: ...", Map.of()),
new Text(List.of(), "--resolve-relaxed: ...", Map.of())
), Map.of())), Map.of())), Map.of())), Map.of())),
Map.of())),
body.children());
}

@Test
void orderedList() {
final var body = new Parser().parseBody(new Reader(List.of("""
Expand Down
2 changes: 1 addition & 1 deletion env-manager/src/main/java/io/yupiik/dev/command/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.joining;

@Command(name = "run", description = "Similar to `env` spirit but for aliases or execution in the shell context of the `.yemrc` file.`." +
@Command(name = "run", description = "Similar to `env` spirit but for aliases or execution in the shell context of the `.yemrc` file." +
" Important: it is recommended to use `--` to separate yem args from the command: `yem run --rc .yemrc -- mvn clean package`." +
" Note that the first arg after `--` will be tested against an alias in the `.yemrc` (or global one) so you can pre-define complex commands there." +
" Ex: `build.alias = mvn package` in `.yemrc` will enable to run `yem run -- build` which will actually execute `mvn package` and if you configure maven version (`maven.version = 3.9.6` for example) the execution environment will use the right distribution.")
Expand Down

0 comments on commit a3c20f9

Please sign in to comment.