diff options
author | TomaszSzt <87855864+TomaszSzt@users.noreply.github.com> | 2021-11-18 15:38:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-18 15:38:54 +0100 |
commit | ebbd27be8c47579db837d4d174905c4ef1c6de39 (patch) | |
tree | cb5bc00de3fa108767c559ba2116d5d8691d6605 /src/main/java/com/gitblit | |
parent | 9142f1f74d5ab60335eb9f7d38b946c75f109460 (diff) | |
download | gitblit-ebbd27be8c47579db837d4d174905c4ef1c6de39.tar.gz gitblit-ebbd27be8c47579db837d4d174905c4ef1c6de39.zip |
Fixes external links broken in markdown rendering (#1392)
* This commit fixes what was broken in commit
https://github.com/gitblit/gitblit/commit/b23269acc0f460f583311c679d751925b8402563
due to #1358 issue
Diffstat (limited to 'src/main/java/com/gitblit')
-rw-r--r-- | src/main/java/com/gitblit/wicket/MarkupProcessor.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/wicket/MarkupProcessor.java b/src/main/java/com/gitblit/wicket/MarkupProcessor.java index 7facc59e..300039bc 100644 --- a/src/main/java/com/gitblit/wicket/MarkupProcessor.java +++ b/src/main/java/com/gitblit/wicket/MarkupProcessor.java @@ -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); |