Skip to content

Commit

Permalink
fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Feb 14, 2024
1 parent a3c20f9 commit 7b66691
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ private Map<String, String> parseOptions(final String options) {
.or(() -> mapIf("example", "exampleblock", "", options))
.or(() -> mapIf("verse", "verseblock", "", options))
.or(() -> mapIf("quote", "quoteblock", "attribution", options))
.orElseGet(() -> doParseOptions(options, ""));
.orElseGet(() -> doParseOptions(options, "", true));
}

private Optional<Map<String, String>> mapIf(final String matcher, final String role,
Expand All @@ -1230,7 +1230,7 @@ private Optional<Map<String, String>> mapIf(final String matcher, final String r
if (options.startsWith(matcher + ",")) {
return of(merge(
role == null ? Map.of() : Map.of("role", role),
doParseOptions(options.substring(matcher.length() + ",".length()).strip(), defaultKey)));
doParseOptions(options.substring(matcher.length() + ",".length()).strip(), defaultKey, true)));
}

return empty();
Expand Down Expand Up @@ -1420,7 +1420,7 @@ private boolean isLink(final String link) {
link.startsWith("mailto:");
}

private Map<String, String> doParseOptions(final String options, final String defaultKey) {
private Map<String, String> doParseOptions(final String options, final String defaultKey, final boolean nestedOptsSupport) {
final var map = new HashMap<String, String>();
final var key = new StringBuilder();
final var value = new StringBuilder();
Expand Down Expand Up @@ -1448,9 +1448,11 @@ private Map<String, String> doParseOptions(final String options, final String de
if (!key.isEmpty()) {
flushOption(defaultKey, key, value, map);
}
final var opts = map.remove("opts");
if (opts != null) {
map.putAll(doParseOptions(opts, "opts"));
if (nestedOptsSupport) {
final var opts = map.remove("opts");
if (opts != null) {
map.putAll(doParseOptions(opts, "opts", false));
}
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@ public void visitCode(final Code element) {
builder.append(" <li>\n");
state.inCallOut = true;
state.nowrap = true;
visitElement(c.text());
if (c.text() instanceof Paragraph p && p.options().isEmpty()) {
p.children().forEach(this::visitElement);
} else {
visitElement(c.text());
}
state.inCallOut = false;
state.nowrap = nowrap;
builder.append(" </li>\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,20 @@ void table() {
body.children());
}

@Test
void tableOpts() {
final var body = new Parser().parseBody(
new Reader(List.of("""
[opts="header"]
|===
|c1
|===
""".split("\n"))),
null);
assertEquals(
List.of(new Table(List.of(List.of(new Text(List.of(), "c1", Map.of()))), Map.of("opts", "header"))),
body.children());
}

@Test
void tableMultiple() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,89 @@ public record Foo() {}
""");
}

@Test
void callout() {
assertRenderingContent("""
== Enums
Enumerations (de)serialization behavior can be customized by using some specific methods:
[source,java]
----
public enum MyEnum {
A, B;
public String toJsonString() { <1>
return this == A ? "first" : "second";
}
public static MyEnum fromJsonString(final String v) { <2>
return switch (v) {
case "first" -> MyEnum.A;
case "second" -> MyEnum.B;
default -> throw new IllegalArgumentException("Unsupported '" + v + "'");
};
}
}
----
<.> `toJsonString` is an instance method with no parameter used to replace `.name()` call during serialization,
<.> `fromJsonString` is a static method with a `String` parameter used to replace `.valueOf(String)` call during deserialization.
""", """
<div class="sect1" id="_enums">
<h2>Enums</h2>
<div class="sectionbody">
<div class="paragraph">
<p>
Enumerations (de)serialization behavior can be customized by using some specific methods:
</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public enum MyEnum {
A, B;
public String toJsonString() { <b class="conum">(1)</b>
return this == A ? &quot;first&quot; : &quot;second&quot;;
}
public static MyEnum fromJsonString(final String v) { <b class="conum">(2)</b>
return switch (v) {
case &quot;first&quot; -&gt; MyEnum.A;
case &quot;second&quot; -&gt; MyEnum.B;
default -&gt; throw new IllegalArgumentException(&quot;Unsupported '&quot; + v + &quot;'&quot;);
};
}
}</code></pre>
</div>
</div>
<div class="colist arabic">
<ol>
<li>
<code>toJsonString</code> <span>
is an instance method with no parameter used to replace\s
</span>
<code>.name()</code> <span>
call during serialization,
</span>
</li>
<li>
<code>fromJsonString</code> <span>
is a static method with a\s
</span>
<code>String</code> <span>
parameter used to replace\s
</span>
<code>.valueOf(String)</code> <span>
call during deserialization.
</span>
</li>
</ol>
</div>
</div>
</div>
""");
}

@Test
void ol() {
assertRenderingContent("""
Expand Down Expand Up @@ -557,7 +640,7 @@ void codeInSectionTitle() {
void codeInSectionTitleComplex() {
assertRenderingContent("""
== Title :: foo `bar.json`
foo""", """
<div class="sect1" id="_title__foo_barjson">
<h2>Title :: foo <code>bar.json</code></h2>
Expand Down

0 comments on commit 7b66691

Please sign in to comment.