Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom styling for Javadocs within Eclipse

I've discovered that I can add some CSS styling to Javadocs in Eclipse, to create some nice effects for the inline code hovers.

Sample javadoc:

/**
 * <p>This is a general description of the class.<p>
 * 
 * <p>Here is a useful direct quote:</p>
 * 
 * <div style="background-color:white; border: 1px solid gray; margin: 1em 2.5em; padding: 0em 0.5em">
 *   <p>This quote has a list:</p>
 *   <ul>
 *     <li>Item 1</li>
 *     <li>Item 2</li>
 *   </ul>
 * </div>
 *
 */
public class SSCCE {

}

Sample result: Javadoc hover example

I'd like to take advantage of this more in my code, but it would be much better if I could use something like <div class="box"> instead of setting the style attribute manually, for the following reasons:

  1. If I later decide to tweak the style, I might have to change hundreds of Javadoc comments
  2. At the moment, I only care about the appearance within Eclipse. However, if I ever export the Javadocs to HTML, I might want the HTML version to have a different style than the Eclipse version.

Is it possible to do this in Eclipse, perhaps with a plugin?

like image 776
Kevin K Avatar asked Oct 22 '22 21:10

Kevin K


1 Answers

Through experimentation I discovered I could link to a stylesheet using a <link> tag with an href relative to the .java file location. This does address issue #1 mentioned in the question, but personally I think it's too cumbersome and probably won't use it. It also doesn't solve issue #2 (if anything, it makes it worse).

I'm still open to suggestions for better solutions! I suspect though it would take an Eclipse plugin to fully achieve what I really want to do.

[project-root]/src/org/foobar/Foo.java:

package org.foobar;

/**
 * <link rel="stylesheet" type="text/css" href="../../../javadoc.css"/>
 * 
 * <p class="orange">Foo doc, in orange</p>
 */
public class Foo {

}

[project-root]/javadoc.css

p.orange {
    color: orange;
}
like image 117
Kevin K Avatar answered Oct 24 '22 18:10

Kevin K