我正在尝试格式化以下 Javadoc,但我不知道如何。
示例输入:
/**
* 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
*/
当我按下“格式”时,我想看到这个:
/**
* 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 和 NetBeans 很容易做到这一点。 IntelliJ,如果我将它配置为换行(我需要)它还会加入标签,除了 <p>
. (设置 -> 编辑器 -> 代码样式 -> Java -> JavaDoc -> 其他 -> 在右边距处换行)。它看起来像这样:
/**
* 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 Formatter 插件。我觉得 IntelliJ 本身应该能够处理这种基本行为,或者任何人应该如何以正常方式格式化他们的 Javadoc?
最佳答案
- 打开首选项
- 选择编辑器> 代码样式> Java
- 打开 JavaDoc 选项卡
设置以下选项
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点击确定
- 然后只需使用代码> 重新格式化代码
当然,您可以根据自己的...偏好调整偏好。此设置将重新对齐文本以适合页边距,但您必须在格式化之前将
- 标签放在新行上。
关于intellij-idea - IntelliJ : wrap javadoc text but not markup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36268493/