Skip to content

Commit 53bc72b

Browse files
fix: add wrapping for package summary (#284)
* fix: add wrapping for package summary * chore: use regex matcher instead * chore: handle no match edge case * chore: simplify logic * chore: update goldens
1 parent 4a2acc1 commit 53bc72b

20 files changed

Lines changed: 86 additions & 58 deletions

third_party/docfx-doclet-143274/src/main/java/com/microsoft/build/PackageOverviewFile.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.microsoft.build.BuilderUtil.LANGS;
44

55
import com.fasterxml.jackson.annotation.JsonIgnore;
6+
import com.google.common.annotations.VisibleForTesting;
67
import com.google.common.collect.ImmutableList;
78
import com.google.docfx.doclet.RepoMetadata;
89
import com.microsoft.lookup.PackageLookup;
@@ -376,7 +377,7 @@ private static String createHtmlTable(
376377
.append("<td><a href=\"")
377378
.append(linkPrefix + packageChildSummary.uid)
378379
.append("\">")
379-
.append(packageChildSummary.uid)
380+
.append(withLineBreaks(packageChildSummary.uid))
380381
.append("</a></td>\n")
381382
.append("<td>\n")
382383
.append(packageChildSummary.summary != null ? packageChildSummary.summary : "")
@@ -417,4 +418,18 @@ public String getFileName() {
417418
public void setFileName(String fileName) {
418419
this.fileName = fileName;
419420
}
421+
422+
@VisibleForTesting
423+
static String withLineBreaks(String uid) {
424+
Pattern p = Pattern.compile("[a-zA-Z\\d][a-z\\d]+\\.|[A-Z][a-z]+");
425+
Matcher m = p.matcher(uid);
426+
if (!m.find()) {
427+
return uid;
428+
}
429+
StringBuilder s = new StringBuilder();
430+
while (m.find()) {
431+
m.appendReplacement(s, "<wbr>" + m.group());
432+
}
433+
return s.toString();
434+
}
420435
}

third_party/docfx-doclet-143274/src/test/java/com/microsoft/build/PackageOverviewFileTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,17 @@ public void testExtractPackageBaseURIBeforeVersion() {
4545
assertEquals("N/A", packageInfo_4.get(0));
4646
assertEquals("N/A", packageInfo_4.get(1));
4747
}
48+
49+
@Test
50+
public void testWithLineBreaks() {
51+
String uid =
52+
"com.google.cloud.securitycenter.v2.AttackPathName.OrganizationLocationSimulationValuedResourceAttackPathBuilder";
53+
String converted = PackageOverviewFile.withLineBreaks(uid);
54+
assertEquals(
55+
"com.<wbr>google.<wbr>cloud.<wbr>securitycenter.<wbr>v2.<wbr>Attack<wbr>Path<wbr>Name.<wbr>Organization<wbr>Location<wbr>Simulation<wbr>Valued<wbr>Resource<wbr>Attack<wbr>Path<wbr>Builder",
56+
converted);
57+
58+
String nonMatchable = "123non-matchable";
59+
assertEquals(nonMatchable, PackageOverviewFile.withLineBreaks(nonMatchable));
60+
}
4861
}

third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.ExceptionHandler.Interceptor.RetryResult.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,4 @@ references:
273273
- uid: "T>valueOf(java.lang.Class"
274274
name: "T>valueOf(Class"
275275
nameWithType: "T>valueOf(Class"
276-
fullName: "T>valueOf(java.lang.Class"
276+
fullName: "T>valueOf(java.lang.Class"

third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ Class</th>
1919
<th>
2020
Description</th>
2121
<tr>
22-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.agreements.AgreementDetailsCollectionOperations">com.microsoft.samples.agreements.AgreementDetailsCollectionOperations</a></td>
22+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.agreements.AgreementDetailsCollectionOperations">com.<wbr>microsoft.<wbr>samples.<wbr>agreements.<wbr>Agreement<wbr>Details<wbr>Collection<wbr>Operations</a></td>
2323
<td>
2424

2525
<strong>Deprecated.</strong> <em>Use <xref uid="AgreementMetaData" data-throw-if-not-resolved="false">AgreementMetaData</xref> instead.</em>
2626

2727
Agreement details collection operations implementation class.</td>
2828
</tr>
2929
<tr>
30-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.agreements.AgreementMetaData">com.microsoft.samples.agreements.AgreementMetaData</a></td>
30+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.agreements.AgreementMetaData">com.<wbr>microsoft.<wbr>samples.<wbr>agreements.<wbr>Agreement<wbr>Meta<wbr>Data</a></td>
3131
<td>
3232
The AgreementMetaData provides metadata about the agreement type that partner can provide
3333
confirmation of customer acceptance.</td>
3434
</tr>
3535
<tr>
36-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.agreements.ResourceCollection">com.microsoft.samples.agreements.ResourceCollection</a></td>
36+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.agreements.ResourceCollection">com.<wbr>microsoft.<wbr>samples.<wbr>agreements.<wbr>Resource<wbr>Collection</a></td>
3737
<td>
3838
Contains a collection of resources with JSON properties to represent the output Type of objects
3939
in collection</td>
@@ -48,7 +48,7 @@ Interface</th>
4848
<th>
4949
Description</th>
5050
<tr>
51-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.agreements.IAgreementDetailsCollection">com.microsoft.samples.agreements.IAgreementDetailsCollection</a></td>
51+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.agreements.IAgreementDetailsCollection">com.<wbr>microsoft.<wbr>samples.<wbr>agreements.I<wbr>Agreement<wbr>Details<wbr>Collection</a></td>
5252
<td>
5353

5454
<strong>Deprecated.</strong> <em>This one is deprecated :(</em>

third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.commentinheritance.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ Class</th>
1919
<th>
2020
Description</th>
2121
<tr>
22-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Animal">com.microsoft.samples.commentinheritance.Animal</a></td>
22+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Animal">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Animal</a></td>
2323
<td>
2424
Animal.</td>
2525
</tr>
2626
<tr>
27-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Dog">com.microsoft.samples.commentinheritance.Dog</a></td>
27+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Dog">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Dog</a></td>
2828
<td>
2929
Canine and man's best friend.</td>
3030
</tr>
3131
<tr>
32-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Herbivorous.Plant">com.microsoft.samples.commentinheritance.Herbivorous.Plant</a></td>
32+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Herbivorous.Plant">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Herbivorous.<wbr>Plant</a></td>
3333
<td>
3434
</td>
3535
</tr>
3636
<tr>
37-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Mammal">com.microsoft.samples.commentinheritance.Mammal</a></td>
37+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Mammal">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Mammal</a></td>
3838
<td>
3939
Mammal.</td>
4040
</tr>
@@ -48,27 +48,27 @@ Interface</th>
4848
<th>
4949
Description</th>
5050
<tr>
51-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Carnivorous">com.microsoft.samples.commentinheritance.Carnivorous</a></td>
51+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Carnivorous">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Carnivorous</a></td>
5252
<td>
5353
Marks an Animal that eats other animals.</td>
5454
</tr>
5555
<tr>
56-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Herbivorous">com.microsoft.samples.commentinheritance.Herbivorous</a></td>
56+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Herbivorous">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Herbivorous</a></td>
5757
<td>
5858
Marks animals that eat plants.</td>
5959
</tr>
6060
<tr>
61-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Omnivorous">com.microsoft.samples.commentinheritance.Omnivorous</a></td>
61+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Omnivorous">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Omnivorous</a></td>
6262
<td>
6363
Eats plants and animals.</td>
6464
</tr>
6565
<tr>
66-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Organism">com.microsoft.samples.commentinheritance.Organism</a></td>
66+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Organism">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Organism</a></td>
6767
<td>
6868
</td>
6969
</tr>
7070
<tr>
71-
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Viviparous">com.microsoft.samples.commentinheritance.Viviparous</a></td>
71+
<td><a href="https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.microsoft.samples.commentinheritance.Viviparous">com.<wbr>microsoft.<wbr>samples.<wbr>commentinheritance.<wbr>Viviparous</a></td>
7272
<td>
7373
Mammals that give birth to young that develop within the mother's body.</td>
7474
</tr>

third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.ProductSearchSettings.Builder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,4 +1608,4 @@ references:
16081608
- uid: "?,?>,java.lang.Void>)"
16091609
name: "?,?>,Void>)"
16101610
nameWithType: "?,?>,Void>)"
1611-
fullName: "?,?>,java.lang.Void>)"
1611+
fullName: "?,?>,java.lang.Void>)"

third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.RecognitionAudio.AudioSourceCase.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,4 @@ references:
365365
- uid: "T>valueOf(java.lang.Class"
366366
name: "T>valueOf(Class"
367367
nameWithType: "T>valueOf(Class"
368-
fullName: "T>valueOf(java.lang.Class"
368+
fullName: "T>valueOf(java.lang.Class"

third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.RecognitionAudio.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,4 +1256,4 @@ references:
12561256
- uid: "ListT>makeMutableCopy(ListT,int)"
12571257
name: "ListT>makeMutableCopy(ListT,int)"
12581258
nameWithType: "ListT>makeMutableCopy(ListT,int)"
1259-
fullName: "ListT>makeMutableCopy(ListT,int)"
1259+
fullName: "ListT>makeMutableCopy(ListT,int)"

third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.SpeechSettings.Builder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,4 +733,4 @@ references:
733733
- uid: "?,?>,java.lang.Void>)"
734734
name: "?,?>,Void>)"
735735
nameWithType: "?,?>,Void>)"
736-
fullName: "?,?>,java.lang.Void>)"
736+
fullName: "?,?>,java.lang.Void>)"

third_party/docfx-doclet-143274/src/test/resources/expected-generated-files/com.microsoft.samples.google.SpeechSettings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,4 +786,4 @@ references:
786786
- uid: "B>toBuilder()"
787787
name: "B>toBuilder()"
788788
nameWithType: "B>toBuilder()"
789-
fullName: "B>toBuilder()"
789+
fullName: "B>toBuilder()"

0 commit comments

Comments
 (0)