Skip to content

Commit ebbd27b

Browse files
authored
Fixes external links broken in markdown rendering (#1392)
* This commit fixes what was broken in commit b23269a due to #1358 issue
1 parent 9142f1f commit ebbd27b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/com/gitblit/wicket/MarkupProcessor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,22 @@ public Rendering render(WikiLinkNode node) {
360360

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

0 commit comments

Comments
 (0)