Fixed IDEA-143120 Javadoc HTML proper formatting

merged HTML lines with "wrapped at right margin" option
This commit is contained in:
Rustam Vishnyakov
2017-12-23 13:35:07 +03:00
parent 4bbec3604f
commit 6a2c34b5d8
2 changed files with 79 additions and 8 deletions
@@ -422,14 +422,8 @@ public class JDParser {
result.add(Pair.create(s1, marks[i]));
}
else {
if (s1.isEmpty() || s1.equals(SELF_CLOSED_P_TAG)) {
if (sb.length() != 0) {
result.add(new Pair<>(sb.toString(), false));
sb.setLength(0);
}
result.add(Pair.create(s1, marks[i]));
}
else if (mySettings.JD_PRESERVE_LINE_FEEDS) {
if (s1.isEmpty() || s1.equals(SELF_CLOSED_P_TAG) || isKeepLineFeedsIn(s1)) {
endParagraph(result, sb);
result.add(Pair.create(s1, marks[i]));
}
else {
@@ -444,6 +438,24 @@ public class JDParser {
return result;
}
private boolean isKeepLineFeedsIn(@NotNull String line) {
return mySettings.JD_PRESERVE_LINE_FEEDS || startsWithTag(line);
}
private static boolean startsWithTag(@NotNull String line) {
if (line.trim().startsWith("<")) {
return line.matches("\\s*</?\\w+>.*");
}
return false;
}
private static void endParagraph(@NotNull List<Pair<String, Boolean>> result, @NotNull StringBuilder sb) {
if (sb.length() > 0) {
result.add(new Pair<>(sb.toString(), false));
sb.setLength(0);
}
}
private interface TagParser {
boolean parse(String tag, String line, JDComment c);
}
@@ -1023,4 +1023,63 @@ module M {
module M {
}""")
}
fun testRichHtml() {
getSettings().WRAP_COMMENTS = true
getSettings().RIGHT_MARGIN = 50
getJavaSettings().JD_ADD_BLANK_AFTER_DESCRIPTION = false
doTextTest(
"""public class Test {
/**
* <h1>A description containing HTML tags</h1>
* <p>
* There might be lists in descriptions like this one:
* <ul>
* <li>Item one</li>
* <li>Item two</li>
* <li>Item three</li>
* </ul>
* which should be left as is, without any tags merged.
* </p>
* @param a Parameter descriptions can also be long but tag
* content should be left intact:
* <ol>
* <li>Another item one</li>
* <li>Item two</li>
* </ol>
*/
void test(int a) {
}
}
""",
"""public class Test {
/**
* <h1>A description containing HTML
* tags</h1>
* <p>
* There might be lists in descriptions like
* this one:
* <ul>
* <li>Item one</li>
* <li>Item two</li>
* <li>Item three</li>
* </ul>
* which should be left as is, without any
* tags merged.
* </p>
* @param a Parameter descriptions can also be
* long but tag content should be
* left intact:
* <ol>
* <li>Another item one</li>
* <li>Item two</li>
* </ol>
*/
void test(int a) {
}
}
"""
)
}
}