Skip to content

Commit

Permalink
Some improvements to Markdown rendering
Browse files Browse the repository at this point in the history
* Treat DCRawText as raw text (don't both splitting lines)
* Some fixes in TagElement range correction
  • Loading branch information
mickaelistria committed Sep 25, 2024
1 parent 9fb5696 commit f2f49c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3491,13 +3491,14 @@ public void endVisit(TagElement tagElement) {
OptionalInt end = ((List<ASTNode>)tagElement.fragments()).stream()
.filter(node -> node.getStartPosition() >= 0 && node.getLength() >= 0)
.mapToInt(node -> node.getStartPosition() + node.getLength())
.min();
.max();
if (start.isPresent() && end.isPresent()) {
if (JavadocConverter.isInline(tagElement)) {
// include some extra wrapping chars ( `{...}` or `[...]`)
tagElement.setSourceRange(start.getAsInt() - 1, end.getAsInt() + 1);
// current heuristic is very approximative as it will fail with whitespace
tagElement.setSourceRange(start.getAsInt() - 1, end.getAsInt() - start.getAsInt() + 2);
} else {
tagElement.setSourceRange(start.getAsInt(), end.getAsInt());
tagElement.setSourceRange(start.getAsInt(), end.getAsInt() - start.getAsInt());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,20 +598,18 @@ private List<IDocElement> convertElementCombiningNodes(List<DCTree> treeElements
boolean shouldCombine = false;
boolean lineBreakBefore = false;
DCTree oneTree = treeElements.get(i);
if( oneTree instanceof DCText || oneTree instanceof DCStartElement || oneTree instanceof DCEndElement || oneTree instanceof DCEntity || oneTree instanceof DCRawText) {
if(oneTree instanceof DCText || oneTree instanceof DCStartElement || oneTree instanceof DCEndElement || oneTree instanceof DCEntity) {
shouldCombine = true;
if((oneTree instanceof DCText dct && dct.text.startsWith("\n"))
|| (oneTree instanceof DCRawText raw && raw.getContent().endsWith("\n"))) {
lineBreakBefore = true;
}
} else {
if( oneTree instanceof DCErroneous derror) {
Stream<IDocElement> de = convertDCErroneousElement(derror);
if( de == null ) {
shouldCombine = true;
if( derror.body.startsWith("{@")) {
lineBreakBefore = true;
}
} else if( oneTree instanceof DCErroneous derror) {
Stream<IDocElement> de = convertDCErroneousElement(derror);
if( de == null ) {
shouldCombine = true;
if( derror.body.startsWith("{@")) {
lineBreakBefore = true;
}
}
}
Expand All @@ -638,7 +636,10 @@ private Stream<? extends IDocElement> convertElement(DCTree javac) {
if (javac instanceof DCText text) {
return splitLines(text, false).map(this::toTextElement);
} else if (javac instanceof DCRawText rawText) {
return splitLines(rawText.getContent(), rawText.getStartPosition(), rawText.getEndPosition(), false).map(this::toTextElement);
TextElement element = this.ast.newTextElement();
commonSettings(element, javac);
element.setText(rawText.getContent());
return Stream.of(element);
} else if (javac instanceof DCIdentifier identifier) {
Name res = this.ast.newName(identifier.getName().toString());
commonSettings(res, javac);
Expand Down

0 comments on commit f2f49c1

Please sign in to comment.