5

I was using </p> tag to break lines in Javadoc. It was both old-fashion and working in Elcipse. Unfortunetely, it does not work in IntelliJ:

enter image description here

As you see, there is no wrap between "to javadoc" and "This is it".

Simultaneously, Eclipse works fine:

enter image description here

Code is follows (don't regard image path -- it is from other test):

package tests.helloworld;

/**
 * This is try to javadoc</p>
 * This is it
 * <img src="/myimage.jpg">
 */
public class Runner {
    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}

UPDATE

Of course generated javadoc is OK in browser:

enter image description here

Dims
  • 47,675
  • 117
  • 331
  • 600
  • 1
    Did you try using proper HTML in your Javadoc (i.e. surround "This is try to javadoc" with both a `

    ` start tag *and* a `

    ` end tag)?
    – Sam Estep Jul 02 '15 at 15:57
  • I wish to use single closing tag, because it conserves typing. It is working everywhere except `IntelliJ`. – Dims Jul 02 '15 at 15:59
  • P.S. Sure, if I use two tags, it shows ok. – Dims Jul 02 '15 at 16:00
  • 2
    In this case, you should just use single `

    ` tags between paragraphs, instead of single `

    ` tags after paragraphs ([random source](http://blog.joda.org/2012/11/javadoc-coding-standards.html)) or use `
    ` tags instead ([other source](http://stackoverflow.com/questions/5260368/javadoc-paragraph-separator)).
    – Sam Estep Jul 02 '15 at 16:00
  • If I use just `

    ` it will affect DOM structure and, consequently, may affect styling (first chunk will not tagged with `

    `).

    – Dims Jul 02 '15 at 16:04
  • 1
    That's true. However, as I've said, simply separating paragraphs with `

    ` tags is conventional.

    – Sam Estep Jul 02 '15 at 16:07
  • P.S. `

    ` is worse than `

    ` because IntelliJ automatically adds closing tag `

    `, so it requires extra efforts to delete it :)
    – Dims Jul 02 '15 at 17:12
  • 1
    Where did you get the `` syntax from? If you *really* don't want to use well-formed HTML, at least use the proper syntax for self-closing elements: `

    `. This works in IntelliJ IDEA, and it won't add an opening tag automatically.
    – Darek Kay Jul 02 '15 at 17:40
  • `` is completely different, than `

    `. Latter is equivalent to `

    ` while former is an orphan tag, which pair is deduced automatically by most browsers (except `IntelliJ`).
    – Dims Jul 02 '15 at 17:54
  • But the result (a line break caused by a new paragraph) is exactly the same. In fact, both `

    ` and `` work *exactly* the same in Chrome - the result is `

    ` (haven't tried other browsers). IntelliJ isn't a browser and I wouldn't expect it fixing this bad-formed syntax. It's nice that Eclipse does this, but it doesn't make your request any more valid. You want to use a single tag, because it conserves typing. Now you've got one (`

    `), with the expected result. If this is still not enough, consider contributing to IntelliJ code.
    – Darek Kay Jul 02 '15 at 19:40

3 Answers3

4

While <p> [...] </p> formatting is probably more concise/understandable, if you just want line breaks you can use <br>:

/**
 * This is try to javadoc<br>
 * This is it
 * <img src="/myimage.jpg">
 */

Example: screenshot example

Chris Sprague
  • 740
  • 1
  • 12
  • 22
4

You'll need to use <p> instead of </p>. The opening tag is required in HTML, while the closing </p> tag may be omitted in certain cases.

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p:

The start tag is required. The end tag may be omitted if the <p> element is immediately followed by an <address>, <article>, <aside>, <blockquote>, <div>, <dl>, <fieldset>, <footer>, <form>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <header>, <hr>, <menu>, <nav>, <ol>, <pre>, <section>, <table>, <ul> or another <p> element, or if there is no more content in the parent element and the parent element is not an <a> element.

In Javadoc, usually there's either another <p> tag or there is no more content in the parent element so this works.

jmiserez
  • 2,991
  • 1
  • 23
  • 34
2

Note: If you searched for JavaDoc using Kotlin:

On IntelliJ IDEA 2020 neither <p></p> nor <br> work for Kotlin, only a blank line.
Even worse, sentences in <p></p> are not displayed at all.

KDoc Documentation

enter image description here

Antonio Noack
  • 309
  • 3
  • 11
Gunnar Bernstein
  • 6,074
  • 2
  • 45
  • 67