1
0
mirror of synced 2026-05-22 18:53:15 +00:00

docs: fix broken class links, format details and usage (#1536)

This commit is contained in:
Yury Semikhatsky
2024-04-03 14:15:22 -07:00
committed by GitHub
parent a917f2ef5c
commit 1a8f5f7746
36 changed files with 2556 additions and 2037 deletions
@@ -102,16 +102,7 @@ abstract class Element {
for (JsonElement item : spec) {
JsonObject node = item.getAsJsonObject();
String type = node.get("type").getAsString();
if ("code".equals(type)) {
if (!node.get("codeLang").getAsString().contains("java")) {
continue;
}
out.add("<pre>{@code");
for (JsonElement line : node.getAsJsonArray("lines")) {
out.add(line.getAsString());
}
out.add("}</pre>");
} else if ("li".equals(type)) {
if ("li".equals(type)) {
String text = node.get("text").getAsString();
if (text.startsWith("extends: ")) {
continue;
@@ -127,15 +118,34 @@ abstract class Element {
}
}
out.add("<li> " + beautify(text) + "</li>");
continue;
} else {
if (currentItemList != null) {
out.add("</" + currentItemList + ">");
currentItemList = null;
}
}
if ("code".equals(type)) {
if (!node.get("codeLang").getAsString().contains("java")) {
continue;
}
out.add("<pre>{@code");
for (JsonElement line : node.getAsJsonArray("lines")) {
out.add(line.getAsString());
}
out.add("}</pre>");
} else {
String paragraph = node.get("text").getAsString();
paragraph = beautify(paragraph);
if ("note".equals(type)) {
paragraph = "<strong>NOTE:</strong> " + paragraph;
Matcher matcher = Pattern.compile("^\\*\\*(.+)\\*\\*$").matcher(paragraph);
// Format **Usage**, **Details** as bold text.
if (matcher.matches()) {
String title = matcher.group(1);
paragraph = "<strong>" + title + "</strong>";
} else {
paragraph = beautify(paragraph);
if ("note".equals(type)) {
paragraph = "<strong>NOTE:</strong> " + paragraph;
}
}
if (!out.isEmpty())
paragraph = "\n<p> " + paragraph;
@@ -173,7 +183,13 @@ abstract class Element {
String[] parts = name.split("\\.");
name = parts[0] + ".on" + toTitle(parts[1]);
}
linkified += "{@link " + name.replace(".", "#") + " " + name + "()}";
String packagePrefix = "";
if (ApiGenerator.isAssertionClass(name.split("\\.")[0])) {
packagePrefix = "com.microsoft.playwright.assertions.";
} else {
packagePrefix = "com.microsoft.playwright.";
}
linkified += "{@link " + packagePrefix + name.replace(".", "#") + " " + name + "()}";
start = matcher.end();
}
linkified += paragraph.substring(start);
@@ -682,8 +698,8 @@ class Method extends Element {
}
if ("PlaywrightAssertions.setDefaultAssertionTimeout".equals(jsonPath)) {
writeJavadoc(params, output, offset);
output.add(offset + "static void setDefaultAssertionTimeout(double milliseconds) {");
output.add(offset + " AssertionsTimeout.setDefaultTimeout(milliseconds);");
output.add(offset + "static void setDefaultAssertionTimeout(double timeout) {");
output.add(offset + " AssertionsTimeout.setDefaultTimeout(timeout);");
output.add(offset + "}");
output.add("");
return;
@@ -1160,7 +1176,11 @@ public class ApiGenerator {
}
private static Predicate<String> isAssertion() {
return className -> className.toLowerCase().contains("assert");
return className -> isAssertionClass(className);
}
static boolean isAssertionClass(String className) {
return className.toLowerCase().contains("assert");
}
// TODO: Remove this predicate once SoftAssertions are implemented.