You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MarkdownPage.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.pages;
  17. import java.text.ParseException;
  18. import org.apache.wicket.PageParameters;
  19. import org.apache.wicket.markup.html.basic.Label;
  20. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  21. import org.eclipse.jgit.lib.Constants;
  22. import org.eclipse.jgit.lib.Repository;
  23. import org.eclipse.jgit.revwalk.RevCommit;
  24. import com.gitblit.utils.JGitUtils;
  25. import com.gitblit.utils.MarkdownUtils;
  26. import com.gitblit.wicket.RepositoryPage;
  27. import com.gitblit.wicket.WicketUtils;
  28. public class MarkdownPage extends RepositoryPage {
  29. public MarkdownPage(PageParameters params) {
  30. super(params);
  31. final String markdownPath = WicketUtils.getPath(params);
  32. Repository r = getRepository();
  33. RevCommit commit = JGitUtils.getCommit(r, objectId);
  34. // markdown page links
  35. add(new Label("blameLink", getString("gb.blame")));
  36. add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
  37. add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
  38. add(new BookmarkablePageLink<Void>("headLink", MarkdownPage.class, WicketUtils.newPathParameter(repositoryName, Constants.HEAD, markdownPath)));
  39. // Read raw markdown content and transform it to html
  40. String markdownText = JGitUtils.getRawContentAsString(r, commit, markdownPath);
  41. String htmlText;
  42. try {
  43. htmlText = MarkdownUtils.transformMarkdown(markdownText);
  44. } catch (ParseException p) {
  45. error(p.getMessage());
  46. htmlText = markdownText;
  47. }
  48. // Add the html to the page
  49. add(new Label("markdownText", htmlText).setEscapeModelStrings(false));
  50. }
  51. @Override
  52. protected String getPageName() {
  53. return getString("gb.markdown");
  54. }
  55. }