Browse Source

Fixes external links broken in markdown rendering (#1392)

* This commit fixes what was broken in commit
b23269acc0
due to #1358 issue
tags/v1.9.2
TomaszSzt 2 years ago
parent
commit
ebbd27be8c
No account linked to committer's email address
1 changed files with 16 additions and 0 deletions
  1. 16
    0
      src/main/java/com/gitblit/wicket/MarkupProcessor.java

+ 16
- 0
src/main/java/com/gitblit/wicket/MarkupProcessor.java View File

@@ -360,6 +360,22 @@ public class MarkupProcessor {

@Override
public Rendering render(ExpLinkNode node, String text) {
// Relative file-like MD links needs to be re-mapped to be relative to
// repository name so that they display correctly sub-folder files
// Absolute links must be left un-touched.
// Note: The absolute lack of comments in ExpLinkNode is... well...
// I assume, that getRelativePath is handling "file like" links
// like "/xx/tt" or "../somefolder". What needs to be captured
// is a full URL link. The easiest is to ask java to parse URL
// and let it fail. Shame java.net.URL has no method to validate URL without
// throwing.
try {
new java.net.URL(node.url);
// This is URL, fallback to superclass.
return super.render(node,text);
} catch (java.net.MalformedURLException ignored) {};
// repository-relative link
String path = doc.getRelativePath(node.url);
String url = getWicketUrl(DocPage.class, repositoryName, commitId, path);
return new Rendering(url, text);

Loading…
Cancel
Save