Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: wrap javadoc text but not markup

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?

like image 439
Mark Jeronimus Avatar asked Mar 28 '16 18:03

Mark Jeronimus


People also ask

How to enable soft wrap in IntelliJ?

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.

How to wrap long lines in IntelliJ?

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.

How do you wrap lines in pycharm?

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.


1 Answers

  1. Open Preferences
  2. Select Editor > Code Style > Java
  3. Open the JavaDoc tab
  4. 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

  5. Click OK

  6. Then just use Code > Reformat Code

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.

like image 149
cambunctious Avatar answered Sep 28 '22 03:09

cambunctious