forked from redhat-developer/lsp4ij
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes redhat-developer#376 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
69f8a0c
commit 1887ade
Showing
10 changed files
with
103 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...n/java/com/redhat/devtools/lsp4ij/features/documentation/markdown/CustomLinkRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.redhat.devtools.lsp4ij.features.documentation.markdown; | ||
|
||
import com.vladsch.flexmark.ast.Link; | ||
import com.vladsch.flexmark.html.HtmlWriter; | ||
import com.vladsch.flexmark.html.renderer.*; | ||
import com.vladsch.flexmark.util.ast.Node; | ||
import com.vladsch.flexmark.util.data.DataHolder; | ||
import com.vladsch.flexmark.util.misc.CharPredicate; | ||
import com.vladsch.flexmark.util.sequence.BasedSequence; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class CustomLinkRenderer implements NodeRenderer { | ||
|
||
@Override | ||
public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() { | ||
return Collections.singleton(new NodeRenderingHandler<>(Link.class, this::render)); | ||
} | ||
|
||
private void render(Link node, NodeRendererContext context, HtmlWriter html) { | ||
if (context.isDoNotRenderLinks() /*|| isSuppressedLinkPrefix(node.getUrl(), context)*/) { | ||
context.renderChildren(node); | ||
} else { | ||
ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, node.getUrl().unescape(), null, null); | ||
|
||
html.attr("href", resolvedLink.getUrl()); | ||
|
||
// we have a title part, use that | ||
if (node.getTitle().isNotNull()) { | ||
resolvedLink = resolvedLink.withTitle(node.getTitle().unescape()); | ||
} | ||
|
||
html.attr(resolvedLink.getNonNullAttributes()); | ||
html.srcPos(node.getChars()).withAttr(resolvedLink).tag("a"); | ||
renderChildrenSourceLineWrapped(node, node.getText(), context, html); | ||
html.tag("/a"); | ||
} | ||
} | ||
|
||
private void renderChildrenSourceLineWrapped( | ||
Node node, | ||
BasedSequence nodeChildText, | ||
NodeRendererContext context, | ||
HtmlWriter html | ||
) { | ||
// if have SOFT BREAK or HARD BREAK as child then we open our own span | ||
if (context.getHtmlOptions().sourcePositionParagraphLines && nodeChildText.indexOfAny(CharPredicate.ANY_EOL) >= 0) { | ||
// if (myNextLine > 0) { | ||
// myNextLine--; | ||
// } | ||
|
||
// outputSourceLineSpan(node, node, node, html); | ||
context.renderChildren(node); | ||
html.tag("/span"); | ||
} else { | ||
context.renderChildren(node); | ||
} | ||
} | ||
|
||
public static class Factory implements NodeRendererFactory { | ||
@Override | ||
public NodeRenderer apply(DataHolder options) { | ||
return new CustomLinkRenderer(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters