Skip to content

Commit

Permalink
fix(java): rendering of @see hyperlink leads to errors (#3554)
Browse files Browse the repository at this point in the history
JavaDoc complains about unexpected text when seeing:

```
@see https://example.com/path
```

Apparently it needs to be:

```
@see <a href="https://example.com/path">...</a>
```

Change the JavaDoc renderer.



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
rix0rrr committed May 19, 2022
1 parent f3fec0c commit 9fd3c71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
11 changes: 10 additions & 1 deletion packages/jsii-pacmak/lib/targets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2418,7 +2418,9 @@ class JavaGenerator extends Generator {
tagLines.push(`@return ${docs.returns}`);
}
if (docs.see) {
tagLines.push(`@see ${docs.see}`);
tagLines.push(
`@see <a href="${escape(docs.see)}">${escape(docs.see)}</a>`,
);
}
if (docs.deprecated) {
tagLines.push(`@deprecated ${docs.deprecated}`);
Expand Down Expand Up @@ -3260,3 +3262,10 @@ function splitNamespace(ns: string): [string, string] {
}
return [ns.slice(0, dot), ns.slice(dot + 1)];
}

/**
* Escape a string for dropping into JavaDoc
*/
function escape(s: string) {
return s.replace(/["\\<>&]/g, (c) => `&#${c.charCodeAt(0)};`);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9fd3c71

Please sign in to comment.