mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-375516 javadoc: better handling of last line paragraph breaks
#IDEA-375516 Fixed GitOrigin-RevId: fcc5475be92335ed7cb4a0f7dc416eaffa27462d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2f5c73d5ab
commit
5f0e92caa1
+27
-6
@@ -89,15 +89,36 @@ public class JavaDocMarkdownFlavourDescriptor extends GFMFlavourDescriptor {
|
||||
|
||||
ASTNode parent = node.getParent();
|
||||
if (parent != null && parent.getType() == MarkdownElementTypes.MARKDOWN_FILE) {
|
||||
// Check if the next thing is an EOL
|
||||
List<ASTNode> siblings = parent.getChildren();
|
||||
ASTNode nextSibling = siblings.get(Math.min(siblings.size() - 1, siblings.indexOf(node) + 1));
|
||||
if (nextSibling != null && nextSibling.getType() == MarkdownTokenTypes.EOL) {
|
||||
return false;
|
||||
}
|
||||
if (hasEolSiblings(node, 1, true)) return false;
|
||||
if (hasEolSiblings(node, 2, false)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns whether we have eol siblings, skipping over whitespaces.
|
||||
/// @param count The desired number of EOL siblings
|
||||
/// @param forward Whether to search forward or backward
|
||||
private static boolean hasEolSiblings(@NotNull ASTNode node, int count, boolean forward) throws IllegalArgumentException {
|
||||
if (count <= 0) throw new IllegalArgumentException("count must be positive, was " + count);
|
||||
ASTNode parent = node.getParent();
|
||||
if (parent == null) return false;
|
||||
|
||||
List<ASTNode> siblings = node.getParent().getChildren();
|
||||
int nodeChildIndex = siblings.indexOf(node);
|
||||
int direction = forward ? 1 : -1;
|
||||
|
||||
for (int i = nodeChildIndex + direction; i < siblings.size() && i >= 0; i += direction) {
|
||||
if (siblings.get(i).getType() == MarkdownTokenTypes.EOL) {
|
||||
count--;
|
||||
if (count == 0) return true;
|
||||
continue;
|
||||
}
|
||||
if (siblings.get(i).getType() == MarkdownTokenTypes.WHITE_SPACE) continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeTag(@NotNull HtmlGenerator.HtmlGeneratingVisitor visitor, @NotNull String text, @NotNull ASTNode node) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<html><head><base href="placeholder"></head><body><div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://MarkdownInheritedDoc"><code><span style="color:#000000;">MarkdownInheritedDoc</span></code></a></div><div class='definition'><pre><span style="color:#000080;font-weight:bold;">void</span> <span style="color:#000000;">foo</span><span style="">(</span><span style="">)</span></pre></div><div class='content'><p>Markdown variant</p> I am legacy javadoc, I hope no one disturbs my _underlines_ and **astrerisks** <p>Single line markdown</p></div><table class='sections'><tr><td valign='top' class='section'><p>Overrides:</td><td valign='top'><p><a href="psi_element://MarkdownInheritDoc#foo()"><code><span style="color:#000000;">foo</span></code></a> in class <a href="psi_element://MarkdownInheritDoc"><code><span style="color:#000000;">MarkdownInheritDoc</span></code></a></td></table>
|
||||
@@ -0,0 +1,19 @@
|
||||
import java.lang.Override
|
||||
|
||||
class MarkdownInheritDoc {
|
||||
|
||||
/** I am legacy javadoc, I hope no one disturbs my _underlines_ and **astrerisks** */
|
||||
void foo() {}
|
||||
}
|
||||
|
||||
class MarkdownInheritedDoc extends MarkdownInheritDoc {
|
||||
|
||||
/// Markdown variant
|
||||
/// {@inheritDoc}
|
||||
///
|
||||
/// Single line markdown
|
||||
@Override
|
||||
void foo() {
|
||||
super.foo();
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
<code><span style="">{@link java.lang.String niceLink}</span></code></p><p>No markdown markup is interpreted inside them
|
||||
<code><span style="">_Hello_ <code></span></code></p><p>Code span inside a link
|
||||
<a href="psi_element://java.lang.String">my text with <code>a code span</code>!</a></p><p>This is a broken inline code span
|
||||
`Start of broken code span</p>end of broken code span`</div><table class='sections'><p></table>
|
||||
`Start of broken code span</p><p>end of broken code span`</p></div><table class='sections'><p></table>
|
||||
@@ -0,0 +1 @@
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#000080;font-weight:bold;">class</span> <span style="color:#000000;">MarkdownJepExample</span></pre></div><div class='content'><p>Paragraph one</p><p>Paragraph two (eof)</p></div><table class='sections'><p></table>
|
||||
@@ -0,0 +1,4 @@
|
||||
/// Paragraph one
|
||||
///
|
||||
/// Paragraph two (eof)
|
||||
class MarkdownJepExample {}
|
||||
@@ -1 +1 @@
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#000080;font-weight:bold;">class</span> <span style="color:#000000;">MarkdownCodeBlock</span></pre></div><div class='content'><p><a href="psi_element://java.util.HashMap"><code><span style="color:#0000ff;">java.util.HashMap</span></code></a></p><a href="psi_element://java.util.Collections#EMPTY_LIST">The default empty collection</a></div><table class='sections'><p></table>
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><span style="color:#000080;font-weight:bold;">class</span> <span style="color:#000000;">MarkdownCodeBlock</span></pre></div><div class='content'><p><a href="psi_element://java.util.HashMap"><code><span style="color:#0000ff;">java.util.HashMap</span></code></a></p><p><a href="psi_element://java.util.Collections#EMPTY_LIST">The default empty collection</a></p></div><table class='sections'><p></table>
|
||||
+6
@@ -199,11 +199,17 @@ public class JavaDocInfoGeneratorTest extends JavaCodeInsightTestCase {
|
||||
PsiClass outerClass = ((PsiJavaFile) myFile).getClasses()[1];
|
||||
verifyJavaDoc(outerClass.getMethods()[0]);
|
||||
}
|
||||
public void testMarkdownInheritDocSingleLine() {
|
||||
configureByFile();
|
||||
PsiClass outerClass = ((PsiJavaFile) myFile).getClasses()[1];
|
||||
verifyJavaDoc(outerClass.getMethods()[0]);
|
||||
}
|
||||
public void testMarkdownInlineWithTags(){
|
||||
configureByFile();
|
||||
PsiClass outerClass = ((PsiJavaFile) myFile).getClasses()[0];
|
||||
verifyJavaDoc(outerClass.getMethods()[0]);
|
||||
}
|
||||
public void testMarkdownParagraphSeparation() { doTestClass(); }
|
||||
public void testMarkdownJepExample(){ doTestMethod(); }
|
||||
public void testHtmlCodeInMarkdown() { doTestMethod(); }
|
||||
public void testMarkdownInlineCodeBlock() { doTestClass(); }
|
||||
|
||||
Reference in New Issue
Block a user