spring-io / asciidoctor-extensions

Asciidoctor extensions (currently Asciidoctor.js only) developed for the Spring docs.
Apache License 2.0
1 stars 5 forks source link

Javadoc Extension #14

Open rwinch opened 1 week ago

philwebb commented 1 week ago

Initial prototype code is at https://github.com/rwinch/asciidoctor-extensions/tree/javadoc-extension

The idea behind the extension is to easily convert links of the form javadoc:com.example.MyClass[] to a styled link to the javadoc HTML.

Xref Defaults

The default link conversion will depend on the project. The most common formats will be:

Text Formats

We should allow the format of the link text to be changed as needed. We should support the following:

Formats could be specified as an attribute: javadoc:com.example.MyClass[format=full]

Title and Role

We should create links with title and role attributes so that we can have our UI render them nicely and perhaps offer hover hints showing the fully qualified name. E.g.

xref:api:java/com/example/MyClass.html[MyClass,role=javadocref,title=com.example.MyClass]

Alternative Link Formats

We may need to deal with alternative link formats if we want to support xrefs to other modules, components or external locations. One idea would be to support a prefix in the reference. E.g.

Alternative Text

User might want to use their own link text.

javadoc:com.example.MyClass[see this class for details]

Method/Field References

We might want to consider if we should support links to methods or fields inside the javadoc. For example:

javadoc:com.example.MyClass#myMethod(java.lang.String)[]

philwebb commented 1 week ago

Unfortunately it seems like title isn't a valid option on a link so we can't use it. I also can't see any easy way to attach data-... attributes.

The best I've come up with so far is to attach a pseudo class to the outer <code> element. Code for that is in https://github.com/philwebb/asciidoctor-extensions/commit/f819671e51d94bd8bbb68812b5dea8af1e2c622d.