From 43b8a1fc7f8ab0672eaacfb42040a84dc78dcf1b Mon Sep 17 00:00:00 2001 From: Emily Ball Date: Wed, 12 Jan 2022 12:50:07 -0800 Subject: [PATCH] fix: wider support for @links --- .../java/com/microsoft/util/YamlUtil.java | 2 ++ .../google/v1p1alpha/SpeechClient.java | 2 ++ .../java/com/microsoft/util/YamlUtilTest.java | 22 +++++++++++++++++++ ....samples.google.v1p1alpha.SpeechClient.yml | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/util/YamlUtil.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/util/YamlUtil.java index 9487aba6..260537b7 100644 --- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/util/YamlUtil.java +++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/util/YamlUtil.java @@ -32,7 +32,9 @@ public static String cleanupHtml(String text) { .replaceAll("<([A-Z][a-z]+||)>", "<$1>") .replaceAll("`([^`]+)`", "$1") .replaceAll("\\[([^]]+)]\\(([^)]+)\\)", "$1") + .replaceAll("\\{@link *\"([^\\{]+)\" *\\}", "$1") .replaceAll("\\[([^]]+)]\\[([^]]+)\\]", "$1") + .replaceAll("\\{@link *([^\\{\"]+) *\\}", "$1") .replaceAll("==+([^=]+)==+", "

$1

"); } } diff --git a/third_party/docfx-doclet-143274/src/test/java/com/microsoft/samples/google/v1p1alpha/SpeechClient.java b/third_party/docfx-doclet-143274/src/test/java/com/microsoft/samples/google/v1p1alpha/SpeechClient.java index f98b9ce4..d8f00ead 100644 --- a/third_party/docfx-doclet-143274/src/test/java/com/microsoft/samples/google/v1p1alpha/SpeechClient.java +++ b/third_party/docfx-doclet-143274/src/test/java/com/microsoft/samples/google/v1p1alpha/SpeechClient.java @@ -108,6 +108,8 @@ public static final SpeechClient create() throws IOException { /** * Constructs an instance of SpeechClient, using the given settings. The channels are created * based on the settings passed in, or defaults for any settings that are not set. + * Example broken links: {@link "http://tools.ietf.org/html/rfc2616#section-3.7"} + * {@link ApiFutures#immediateFuture(null)}. */ public static final SpeechClient create(com.microsoft.samples.google.SpeechSettings settings) throws IOException { return new SpeechClient(settings); diff --git a/third_party/docfx-doclet-143274/src/test/java/com/microsoft/util/YamlUtilTest.java b/third_party/docfx-doclet-143274/src/test/java/com/microsoft/util/YamlUtilTest.java index d6889fac..c1fad783 100644 --- a/third_party/docfx-doclet-143274/src/test/java/com/microsoft/util/YamlUtilTest.java +++ b/third_party/docfx-doclet-143274/src/test/java/com/microsoft/util/YamlUtilTest.java @@ -143,4 +143,26 @@ public void cleanupHtmlReferenceTest() { assertEquals("[uid]][text]", YamlUtil.cleanupHtml("[uid]][text]")); assertFalse(YamlUtil.cleanupHtml("[text[uid]]").contains("xref")); } + + @Test + public void cleanupHtmlLinkTagWithLinkTest() { + String expectedActual = "{@link \"http://www.bad-way-to-include-link.com#section\"}"; + String expectedResult = "http://www.bad-way-to-include-link.com#section"; + String random = UUID.randomUUID().toString(); + + assertEquals(expectedResult, YamlUtil.cleanupHtml(expectedActual)); + assertEquals(random + expectedResult + random, YamlUtil.cleanupHtml(random + expectedActual + random)); + assertEquals(expectedResult + random + expectedResult, YamlUtil.cleanupHtml(expectedActual + random + expectedActual)); + } + + @Test + public void cleanupHtmlLinkTagNotRecognizedTest() { + String expectedActual = "{@link WeirdLink#didntResolve(null)}"; + String expectedResult = "WeirdLink#didntResolve(null)"; + String random = UUID.randomUUID().toString(); + + assertEquals(expectedResult, YamlUtil.cleanupHtml(expectedActual)); + assertEquals(random + expectedResult + random, YamlUtil.cleanupHtml(random + expectedActual + random)); + assertEquals(expectedResult + random + expectedResult, YamlUtil.cleanupHtml(expectedActual + random + expectedActual)); + } } diff --git a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1p1alpha.SpeechClient.yml b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1p1alpha.SpeechClient.yml index 5ad0e5d2..7139a4e9 100644 --- a/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1p1alpha.SpeechClient.yml +++ b/third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.v1p1alpha.SpeechClient.yml @@ -170,7 +170,7 @@ items: overload: "com.microsoft.samples.google.v1p1alpha.SpeechClient.create*" type: "Method" package: "com.microsoft.samples.google.v1p1alpha" - summary: "Constructs an instance of SpeechClient, using the given settings. The channels are created\n based on the settings passed in, or defaults for any settings that are not set." + summary: "Constructs an instance of SpeechClient, using the given settings. The channels are created\n based on the settings passed in, or defaults for any settings that are not set.\n Example broken links: http://tools.ietf.org/html/rfc2616#section-3.7\n ApiFutures#immediateFuture(null)." syntax: content: "public static final SpeechClient create(SpeechSettings settings)" parameters: