All WikiLinks must be specified relative to the root of the repository.
The displayed link text is stripped to just the document name. Spaces in
the document name are replaced with '-' characters; this is consistent with
wiki syntax and Github.
Change-Id: Id3fb1b5441352d9bacc4993a5b85882db113693b
- Added option to render Markdown commit messages (issue-203)
- Added setting to control creating a repository as --shared on Unix servers (issue-263)
- Added raw links to the commit, commitdiff, and compare pages (issue-319)
+ - Support intradocument linking in Markdown content using [[WikiLinks]] syntax (issue-324)
- Added setting to globally disable anonymous pushes in the receive pack
- Added a normalized diffstat display to the commit, commitdiff, and compare pages
dependencyChanges:
import java.io.StringWriter;\r
\r
import org.apache.commons.io.IOUtils;\r
+import org.pegdown.LinkRenderer;\r
import org.pegdown.PegDownProcessor;\r
\r
/**\r
* @throws java.text.ParseException\r
*/\r
public static String transformMarkdown(String markdown) {\r
+ return transformMarkdown(markdown, null);\r
+ }\r
+\r
+ /**\r
+ * Returns the html version of the markdown source text.\r
+ *\r
+ * @param markdown\r
+ * @return html version of markdown text\r
+ * @throws java.text.ParseException\r
+ */\r
+ public static String transformMarkdown(String markdown, LinkRenderer linkRenderer) {\r
PegDownProcessor pd = new PegDownProcessor(ALL);\r
- String html = pd.markdownToHtml(markdown);\r
+ String html = pd.markdownToHtml(markdown, linkRenderer == null ? new LinkRenderer() : linkRenderer);\r
return html;\r
}\r
\r
gb.noActivityToday = there has been no activity today
gb.anonymousUser= anonymous
gb.commitMessageRenderer = commit message renderer
-gb.diffStat = {0} insertions & {1} deletions
\ No newline at end of file
+gb.diffStat = {0} insertions & {1} deletions
+gb.home = home
\ No newline at end of file
\r
<body>\r
<wicket:extend>\r
- \r
- <!-- header -->\r
+\r
+<div wicket:id="docs"></div>\r
+\r
+<wicket:fragment wicket:id="indexFragment">\r
+ <ul class="nav nav-tabs">\r
+ <li class="active"><a data-toggle="tab" href="#home"><wicket:message key="gb.home">[home]</wicket:message></a></li>\r
+ <li><a data-toggle="tab" href="#pages"><wicket:message key="gb.pages">[pages]</wicket:message></a></li>\r
+ </ul>\r
+ <div class="tab-content">\r
+ <div id="home" wicket:id="index" class="tab-pane active"></div>\r
+ <div id="pages" wicket:id="documents" class="tab-pane"></div>\r
+ </div>\r
+</wicket:fragment>\r
+\r
+<wicket:fragment wicket:id="noIndexFragment">\r
<div style="margin-top:5px;" class="header"><i class="icon-book" style="vertical-align: middle;"></i> <b><span wicket:id="header">[header]</span></b></div>\r
- \r
+ <div wicket:id="documents"></div>\r
+</wicket:fragment>\r
+\r
+<wicket:fragment wicket:id="documentsFragment">\r
<!-- documents --> \r
<table style="width:100%" class="pretty">\r
<tr wicket:id="document">\r
</span> \r
</td>\r
</tr>\r
- </table> \r
+ </table>\r
+</wicket:fragment>\r
</wicket:extend> \r
</body>\r
</html>
\ No newline at end of file
*/\r
package com.gitblit.wicket.pages;\r
\r
+import java.util.Arrays;\r
import java.util.List;\r
\r
+import org.apache.wicket.Component;\r
import org.apache.wicket.PageParameters;\r
import org.apache.wicket.markup.html.basic.Label;\r
import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
+import org.apache.wicket.markup.html.panel.Fragment;\r
import org.apache.wicket.markup.repeater.Item;\r
import org.apache.wicket.markup.repeater.data.DataView;\r
import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
import org.eclipse.jgit.lib.Repository;\r
+import org.eclipse.jgit.revwalk.RevCommit;\r
\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
import com.gitblit.models.PathModel;\r
import com.gitblit.utils.ByteFormat;\r
import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.MarkdownUtils;\r
+import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.CacheControl;\r
import com.gitblit.wicket.CacheControl.LastModified;\r
import com.gitblit.wicket.WicketUtils;\r
super(params);\r
\r
Repository r = getRepository();\r
+ RevCommit head = JGitUtils.getCommit(r, null);\r
List<String> extensions = GitBlit.getStrings(Keys.web.markdownExtensions);\r
List<PathModel> paths = JGitUtils.getDocuments(r, extensions);\r
\r
- final ByteFormat byteFormat = new ByteFormat();\r
+ String doc = null;\r
+ String markdown = null;\r
+ String html = null;\r
+\r
+ List<String> roots = Arrays.asList("home");\r
\r
- add(new Label("header", getString("gb.docs")));\r
+ // try to find a custom index/root page\r
+ for (PathModel path : paths) {\r
+ String name = path.name.toLowerCase();\r
+ if (name.indexOf('.') > -1) {\r
+ name = name.substring(0, name.lastIndexOf('.'));\r
+ }\r
+ if (roots.contains(name)) {\r
+ doc = path.name;\r
+ break;\r
+ }\r
+ }\r
\r
- // documents list\r
+ if (!StringUtils.isEmpty(doc)) {\r
+ // load the document\r
+ String [] encodings = GitBlit.getEncodings();\r
+ markdown = JGitUtils.getStringContent(r, head.getTree(), doc, encodings);\r
+ html = MarkdownUtils.transformMarkdown(markdown, getLinkRenderer());\r
+ }\r
+\r
+ Fragment fragment = null;\r
+ if (StringUtils.isEmpty(html)) {\r
+ // no custom index/root, use the standard document list\r
+ fragment = new Fragment("docs", "noIndexFragment", this);\r
+ fragment.add(new Label("header", getString("gb.docs")));\r
+ } else {\r
+ // custom index/root, use tabbed ui of index/root and document list\r
+ fragment = new Fragment("docs", "indexFragment", this);\r
+ Component content = new Label("index", html).setEscapeModelStrings(false);\r
+ fragment.add(content);\r
+ }\r
+\r
+ // document list\r
+ final String id = getBestCommitId(head);\r
+ final ByteFormat byteFormat = new ByteFormat();\r
+ Fragment docs = new Fragment("documents", "documentsFragment", this);\r
ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);\r
DataView<PathModel> pathsView = new DataView<PathModel>("document", pathsDp) {\r
private static final long serialVersionUID = 1L;\r
PathModel entry = item.getModelObject();\r
item.add(WicketUtils.newImage("docIcon", "file_world_16x16.png"));\r
item.add(new Label("docSize", byteFormat.format(entry.size)));\r
- item.add(new LinkPanel("docName", "list", entry.name, BlobPage.class, WicketUtils\r
- .newPathParameter(repositoryName, entry.commitId, entry.path)));\r
+ item.add(new LinkPanel("docName", "list", entry.name, MarkdownPage.class, WicketUtils\r
+ .newPathParameter(repositoryName, id, entry.path)));\r
\r
// links\r
- item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils\r
- .newPathParameter(repositoryName, entry.commitId, entry.path)));\r
+ item.add(new BookmarkablePageLink<Void>("view", MarkdownPage.class, WicketUtils\r
+ .newPathParameter(repositoryName, id, entry.path)));\r
item.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils\r
- .newPathParameter(repositoryName, entry.commitId, entry.path)));\r
+ .newPathParameter(repositoryName, id, entry.path)));\r
item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils\r
- .newPathParameter(repositoryName, entry.commitId, entry.path)));\r
+ .newPathParameter(repositoryName, id, entry.path)));\r
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils\r
- .newPathParameter(repositoryName, entry.commitId, entry.path)));\r
+ .newPathParameter(repositoryName, id, entry.path)));\r
WicketUtils.setAlternatingBackground(item, counter);\r
counter++;\r
}\r
};\r
- add(pathsView);\r
+ docs.add(pathsView);\r
+ fragment.add(docs);\r
+ add(fragment);\r
}\r
\r
@Override\r
package com.gitblit.wicket.pages;\r
\r
import java.text.MessageFormat;\r
+import java.util.List;\r
\r
import org.apache.wicket.PageParameters;\r
import org.apache.wicket.markup.html.basic.Label;\r
import org.eclipse.jgit.revwalk.RevCommit;\r
\r
import com.gitblit.GitBlit;\r
+import com.gitblit.Keys;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.MarkdownUtils;\r
import com.gitblit.utils.StringUtils;\r
public MarkdownPage(PageParameters params) {\r
super(params);\r
\r
- final String markdownPath = WicketUtils.getPath(params);\r
+ final String path = WicketUtils.getPath(params).replace("%2f", "/").replace("%2F", "/");\r
\r
Repository r = getRepository();\r
RevCommit commit = JGitUtils.getCommit(r, objectId);\r
String [] encodings = GitBlit.getEncodings();\r
+ List<String> extensions = GitBlit.getStrings(Keys.web.markdownExtensions);\r
+\r
+ // Read raw markdown content and transform it to html\r
+ String markdownPath = path;\r
+ String markdownText = JGitUtils.getStringContent(r, commit.getTree(), path, encodings);\r
+ if (StringUtils.isEmpty(markdownText)) {\r
+ String name = path;\r
+ if (path.indexOf('.') > -1) {\r
+ name = path.substring(0, path.lastIndexOf('.'));\r
+ }\r
+\r
+ for (String ext : extensions) {\r
+ String checkName = name + "." + ext;\r
+ markdownText = JGitUtils.getStringContent(r, commit.getTree(), checkName, encodings);\r
+ if (!StringUtils.isEmpty(markdownText)) {\r
+ // found it\r
+ markdownPath = path;\r
+ break;\r
+ }\r
+ }\r
+ }\r
\r
// markdown page links\r
add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,\r
add(new BookmarkablePageLink<Void>("headLink", MarkdownPage.class,\r
WicketUtils.newPathParameter(repositoryName, Constants.HEAD, markdownPath)));\r
\r
- // Read raw markdown content and transform it to html\r
- String markdownText = JGitUtils.getStringContent(r, commit.getTree(), markdownPath, encodings);\r
String htmlText;\r
try {\r
- htmlText = MarkdownUtils.transformMarkdown(markdownText);\r
+ htmlText = MarkdownUtils.transformMarkdown(markdownText, getLinkRenderer());\r
} catch (Exception e) {\r
logger.error("failed to transform markdown", e);\r
+ if (markdownText == null) {\r
+ markdownText = String.format("Markdown document <b>%1$s</b> not found in <em>%2$s</em>", markdownPath, repositoryName);\r
+ }\r
markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);\r
htmlText = StringUtils.breakLinesForHtml(markdownText);\r
}\r
package com.gitblit.wicket.pages;\r
\r
import java.io.Serializable;\r
+import java.io.UnsupportedEncodingException;\r
+import java.net.URLEncoder;\r
import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import org.eclipse.jgit.lib.PersonIdent;\r
import org.eclipse.jgit.lib.Repository;\r
import org.eclipse.jgit.revwalk.RevCommit;\r
+import org.pegdown.LinkRenderer;\r
+import org.pegdown.ast.WikiLinkNode;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
return isOwner;\r
}\r
\r
+ /**\r
+ * Returns a Pegdown/Markdown link renderer which renders WikiLinks.\r
+ *\r
+ * @return a link renderer\r
+ */\r
+ protected LinkRenderer getLinkRenderer() {\r
+ RevCommit head = JGitUtils.getCommit(r, "HEAD");\r
+ final String id = getBestCommitId(head);\r
+ LinkRenderer renderer = new LinkRenderer() {\r
+ @Override\r
+ public Rendering render(WikiLinkNode node) {\r
+ try {\r
+ String path = URLEncoder.encode(node.getText().replace(' ', '-'), "UTF-8");\r
+ String name = node.getText();\r
+ if (name.indexOf('/') > -1) {\r
+ name = name.substring(name.lastIndexOf('/') + 1);\r
+ }\r
+ String url = urlFor(MarkdownPage.class, WicketUtils.newPathParameter(repositoryName, id, path)).toString();\r
+ return new Rendering(url, name);\r
+ } catch (UnsupportedEncodingException e) {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ };\r
+ return renderer;\r
+ }\r
+\r
private class SearchForm extends SessionlessForm<Void> implements Serializable {\r
private static final long serialVersionUID = 1L;\r
\r
String [] encodings = GitBlit.getEncodings();\r
markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);\r
if (isMarkdown) {\r
- htmlText = MarkdownUtils.transformMarkdown(markdownText);\r
+ htmlText = MarkdownUtils.transformMarkdown(markdownText, getLinkRenderer());\r
} else {\r
htmlText = MarkdownUtils.transformPlainText(markdownText);\r
}\r
if (StringUtils.isEmpty(htmlText)) {\r
add(new Label("readme").setVisible(false));\r
} else {\r
- Fragment fragment = new Fragment("readme", isMarkdown ? "markdownPanel" : "plaintextPanel");\r
+ Fragment fragment = new Fragment("readme", isMarkdown ? "markdownPanel" : "plaintextPanel", this);\r
fragment.add(new Label("readmeFile", readme));\r
// Add the html to the page\r
Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false);\r
border:0px;\r
padding: 0;\r
line-height: 1.35em;\r
- vertical-align:top;\r
}\r
\r
table {\r
padding: 3px;\r
border: 1px solid #ddd;\r
border-bottom: 0;\r
- border-radius: 3px 3px 0 0;\r
font-weight: bold;\r
font-family: Helvetica,arial,freesans,clean,sans-serif;\r
}\r
margin:0 0 2px;\r
padding:7px 14px; \r
border:1px solid #ddd;\r
- border-radius: 3px;\r
- -webkit-border-radius:3px;\r
- -moz-border-radius:3px;border-radius:3px;\r
}\r
\r
div.header a, div.commitHeader a {\r
li.L7,\r
li.L9 { background: #fafafa !important; }\r
\r
+div.markdown {\r
+ max-width: 900px;\r
+}\r
+\r
div.markdown pre {\r
- background-color: #F5F5F5;\r
- border: 1px solid rgba(0, 0, 0, 0.15);\r
+ background-color: rgb(251, 251, 251);\r
+ border: 1px solid rgb(221, 221, 221);\r
border-radius: 4px 4px 4px 4px;\r
display: block;\r
font-size: 12px;\r
}\r
\r
div.markdown code {\r
- background-color: #ffffe0;\r
- border: 1px solid orange;\r
+ background-color: rgb(251, 251, 251);\r
+ border: 1px solid rgb(221, 221, 221);\r
border-radius: 3px;\r
padding: 0 0.2em;\r
}\r