Skip to content

Commit

Permalink
[23] [markdown] JDT is erratic in rendering markdown with newline cha…
Browse files Browse the repository at this point in the history
…racters as unicode (#3256)

#3256
  • Loading branch information
jarthana authored Nov 8, 2024
1 parent 2e87a52 commit dd9a963
Show file tree
Hide file tree
Showing 109 changed files with 308 additions and 3,247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3341,7 +3341,7 @@ protected int readToken() throws InvalidInputException {
}

protected boolean readMarkdownEscapedToken(int expectedToken) throws InvalidInputException {
if (!this.markdown)
if (!this.markdown || (this.tagValue != TAG_LINK_VALUE && this.tagValue != TAG_LINKPLAIN_VALUE))
return readToken() == expectedToken;
if (this.currentTokenType < 0) {
this.tokenPreviousPosition = this.scanner.currentPosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ protected boolean parseMarkdownLinks(int previousPosition) throws InvalidInputEx
}
int eofBkup = this.scanner.eofPosition;
this.scanner.resetTo(start, Math.max(this.javadocEnd, this.index));
this.tagValue = TAG_LINK_VALUE;
valid = parseReference(true);
this.tagValue = NO_TAG_VALUE;
this.scanner.eofPosition = eofBkup;
this.markdownHelper.resetLineStart();
return valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,24 @@ protected final boolean scanForTextBlockBeginning() {
}
return false;
}
protected final boolean lineBeginsWithMarkdown() {
protected final boolean lineBeginsWithMarkdown() throws InvalidInputException {
try {
int temp = this.currentPosition;
int count = 0;
// The scanner is already at \r, look for matching \n
if (this.currentCharacter == '\r' && this.source[temp] == '\n') {
temp++;
if (this.currentCharacter == '\r') {
char c = this.source[temp];
if (c == '\\') {
if (this.source[temp+1] == 'u') {
getNextUnicodeChar();
if (this.currentCharacter == '\n') {
pushUnicodeLineSeparator();
}
temp = this.currentPosition;
}
} else if (c == '\n') {
temp++;
}
}
while(true) {
char c = this.source[temp++];
Expand Down Expand Up @@ -1891,7 +1902,7 @@ protected int getNextToken0() throws InvalidInputException {
previous = this.currentPosition;
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\')
&& (this.source[this.currentPosition] == 'u')) {
//-------------unicode traitement ------------
//-------------unicode treatement ------------
getNextUnicodeChar();
isUnicode = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -27,6 +27,7 @@ public class ASTConverterJavadocFlattener extends ASTVisitor {
private final StringBuilder buffer;
private final int indent = 0;
private final String comment;
private boolean markdown = false;

/**
* Creates a new AST printer.
Expand Down Expand Up @@ -91,13 +92,20 @@ public boolean visit(BlockComment node) {
* @see ASTVisitor#visit(Javadoc)
*/
public boolean visit(Javadoc javadoc) {
try {
this.markdown = javadoc.isMarkdown();
} catch(UnsupportedOperationException usoe) {
// nothing
}
printIndent();
this.buffer.append("/**");//$NON-NLS-1$
if (!this.markdown)
this.buffer.append("/**");//$NON-NLS-1$
for (Iterator it = javadoc.tags().iterator(); it.hasNext(); ) {
ASTNode e = (ASTNode) it.next();
e.accept(this);
}
this.buffer.append("\n */\n");//$NON-NLS-1$
if (!this.markdown)
this.buffer.append("\n */\n");//$NON-NLS-1$
return false;
}

Expand Down Expand Up @@ -150,13 +158,15 @@ public boolean visit(MethodRef node) {
this.buffer.append("(");//$NON-NLS-1$
for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
MethodRefParameter e = (MethodRefParameter) it.next();
e.accept(this);
if (!this.markdown) {
e.accept(this);
}
if (it.hasNext()) {
this.buffer.append(",");//$NON-NLS-1$
}
}
this.buffer.append(")");//$NON-NLS-1$
return true;
return false;
}

/*
Expand All @@ -177,16 +187,24 @@ public boolean visit(MethodRefParameter node) {
* @since 3.0
*/
public boolean visit(TagElement node) {
String tagName = node.getTagName();
boolean isLink = this.markdown && tagName != null && tagName.equals("@link");
if (node.isNested()) {
// nested tags are always enclosed in braces
this.buffer.append("{");//$NON-NLS-1$
if (isLink)
this.buffer.append("[");//$NON-NLS-1$
else
this.buffer.append("{");//$NON-NLS-1$
} else {
// top-level tags always begin on a new line
this.buffer.append("\n * ");//$NON-NLS-1$
if (this.markdown)
this.buffer.append("\n/// ");//$NON-NLS-1$
else
this.buffer.append("\n * ");//$NON-NLS-1$
}
boolean previousRequiresWhiteSpace = false;
if (node.getTagName() != null) {
this.buffer.append(node.getTagName());
if (tagName != null && !isLink) {
this.buffer.append(tagName);
previousRequiresWhiteSpace = true;
}
boolean previousRequiresNewLine = false;
Expand All @@ -196,7 +214,10 @@ public boolean visit(TagElement node) {
// but Name, MemberRef, MethodRef, and nested TagElement do not include white space
boolean currentIncludesWhiteSpace = (e instanceof TextElement);
if (previousRequiresNewLine && currentIncludesWhiteSpace) {
this.buffer.append("\n * ");//$NON-NLS-1$
if (this.markdown)
this.buffer.append("\n/// ");//$NON-NLS-1$
else
this.buffer.append("\n * ");//$NON-NLS-1$
}
previousRequiresNewLine = currentIncludesWhiteSpace;
// add space if required to separate
Expand All @@ -207,7 +228,10 @@ public boolean visit(TagElement node) {
previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement);
}
if (node.isNested()) {
this.buffer.append("}");//$NON-NLS-1$
if (isLink)
this.buffer.append("]");//$NON-NLS-1$
else
this.buffer.append("}");//$NON-NLS-1$
}
return false;
}
Expand Down
Loading

0 comments on commit dd9a963

Please sign in to comment.