Skip to content

Commit

Permalink
[asciidoc] enable to have adoc in description list keys
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Jan 30, 2024
1 parent afd1b03 commit 4285f41
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static io.yupiik.asciidoc.model.Element.ElementType.DESCRIPTION_LIST;

public record DescriptionList(Map<String, Element> children, Map<String, String> options) implements Element {
public record DescriptionList(Map<Element, Element> children, Map<String, String> options) implements Element {
@Override
public ElementType type() {
return DESCRIPTION_LIST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ private Optional<Admonition> parseAdmonition(final Reader reader,
private DescriptionList parseDescriptionList(final Reader reader, final String prefix,
final ContentResolver resolver,
final Map<String, String> currentAttributes) {
final var children = new LinkedHashMap<String, Element>(2);
final var children = new LinkedHashMap<Element, Element>(2);
String next;
final var buffer = new ArrayList<String>();
Matcher matcher;
Expand All @@ -1099,7 +1099,8 @@ private DescriptionList parseDescriptionList(final Reader reader, final String p
}
final var element = parseParagraph(new Reader(buffer), Map.of(), resolver, currentAttributes, true);
final var unwrapped = unwrapElementIfPossible(element);
children.put(matcher.group("name"), unwrapped);
final var key = doParse(new Reader(List.of(matcher.group("name"))), l -> true, resolver, currentAttributes, false);
children.put(key.size() == 1 ? key.get(0) : new Paragraph(key, Map.of("nowrap", "true")), unwrapped);
last = unwrapped;
} else { // nested
reader.rewind();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ default void visitOrderedList(final OrderedList element) {
}

default void visitDescriptionList(final DescriptionList element) {
element.children().values().forEach(this::visitElement);
element.children().forEach((key, value) -> {
visitElement(key);
visitElement(value);
});
}

default void visitMacro(final Macro element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ public void visitDescriptionList(final DescriptionList element) {
writeCommonAttributes(element.options(), null);
builder.append(">\n");
for (final var elt : element.children().entrySet()) {
builder.append(" <dt>").append(escape(elt.getKey())).append("</dt>\n");
builder.append(" <dt>");
visitElement(elt.getKey());
builder.append("</dt>\n");
builder.append(" <dd>\n");
visitElement(elt.getValue());
builder.append("</dd>\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ void descriptionList() {
entry("CPU", new Text(List.of(), "The brain of the computer.", Map.of())),
entry("Hard drive", new Text(List.of(), "Permanent storage for operating system and/or user files.", Map.of())),
entry("RAM", new Text(List.of(), "Temporarily stores information the CPU uses during operation.", Map.of())))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, LinkedHashMap::new)),
.collect(toMap(e -> new Text(List.of(), e.getKey(), Map.of()), Map.Entry::getValue, (a, b) -> a, LinkedHashMap::new)),
Map.of())),
body.children());
}
Expand Down Expand Up @@ -665,7 +665,7 @@ void descriptionListWithList() {
new Text(List.of(), "Bananas", Map.of())),
Map.of()
)))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, LinkedHashMap::new)),
.collect(toMap(e -> new Text(List.of(), e.getKey(), Map.of()), Map.Entry::getValue, (a, b) -> a, LinkedHashMap::new)),
Map.of())),
body.children());
}
Expand Down

0 comments on commit 4285f41

Please sign in to comment.