I'm trying to format the following Javadoc, but I can't figure out how.
Example input:
/**
* Headline.
* <p>
* Lorem ipsum dolor sit amet,
* consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
* <p>
* A list:
* <ul>
* <li>The description above should be wrapped at the right margin, and broken lines should be joined.</li>
* <li>A line starting or ending in a tag should not be joined.</li>
* </ul>
*
* @author Mark Jeronimus
*/
When I press 'format' I want to see this:
/**
* Headline.
* <p>
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
* ut labore et dolore magna aliqua.
* <p>
* A list:
* <ul>
* <li>The description above should be wrapped at the right margin, and broken lines should
* be joined.</li>
* <li>A line starting or ending in a tag should not be joined.</li>
* </ul>
*
* @author Mark Jeronimus
*/
Eclipse and NetBeans do this easily. IntelliJ, if I configure it to wrap text (which I require) it also joins tags except <p>
. (Settings -> Editor -> Code Style -> Java -> JavaDoc -> Other -> Wrap at right margin). It looks like this:
/**
* Headline.
* <p>
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
* ut labore et dolore magna aliqua.
* <p>
* A list: <ul> <li>The description above should be wrapped at the right margin, and broken
* lines should be joined.</li> <li>A line starting or ending in a tag should not be joined.
* </li> </ul>
*
* @author Mark Jeronimus
*/
I tried changing the other settings in the hope some of them interfere with each other, to no avail.
What I don't want is to use the Eclipse Formatter plugin. I feel IntelliJ should be able to handle such basic behavior itself, or how is anyone supposed to format their Javadoc in a normal way?
Press ⇧⌘A (on Mac) or Control+Shift+A (on Windows/Linux) to open the Find Action dialog, and search for "soft-wrap". We get the option to turn on soft-wrap, which will be for this file only. You can click this option to turn soft-wrap on or off.
Wrap if long: break a section of text into lines so that each line fits the configured line length. To configure the line length, open settings Ctrl+Alt+S , navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.
Right-click the left gutter and from the context menu, either select or clear the Soft-Wrap Current Editor option. Keep in mind that these settings affect only the current editor, not a file. To quickly access the settings, select Configure Soft Wraps from the list of options.
Set the following options
Blank lines
✓ After description This is a javadoc standard, other blank lines are optional
Other
✓ Wrap at right margin
✓ Enable leading asterisks
✓ Generate "<p>" on empty lines
✓ Keep empty lines
✗ Preserve line feeds
Click OK
Of course you can tweak the preferences according to your own...preference. This setup will realign the text to fit in the margins but you will have to put the <ul> tag on a new line before formatting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With