Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

MarkdownPage.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.MessageFormat;
  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.GitBlit;
  25. import com.gitblit.utils.JGitUtils;
  26. import com.gitblit.utils.MarkdownUtils;
  27. import com.gitblit.utils.StringUtils;
  28. import com.gitblit.wicket.CacheControl;
  29. import com.gitblit.wicket.CacheControl.LastModified;
  30. import com.gitblit.wicket.WicketUtils;
  31. @CacheControl(LastModified.BOOT)
  32. public class MarkdownPage extends RepositoryPage {
  33. public MarkdownPage(PageParameters params) {
  34. super(params);
  35. final String markdownPath = WicketUtils.getPath(params);
  36. Repository r = getRepository();
  37. RevCommit commit = JGitUtils.getCommit(r, objectId);
  38. String [] encodings = GitBlit.getEncodings();
  39. // markdown page links
  40. add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
  41. WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
  42. add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
  43. WicketUtils.newPathParameter(repositoryName, objectId, markdownPath)));
  44. add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(
  45. repositoryName, objectId, markdownPath)));
  46. add(new BookmarkablePageLink<Void>("headLink", MarkdownPage.class,
  47. WicketUtils.newPathParameter(repositoryName, Constants.HEAD, markdownPath)));
  48. // Read raw markdown content and transform it to html
  49. String markdownText = JGitUtils.getStringContent(r, commit.getTree(), markdownPath, encodings);
  50. String htmlText;
  51. try {
  52. htmlText = MarkdownUtils.transformMarkdown(markdownText);
  53. } catch (Exception e) {
  54. logger.error("failed to transform markdown", e);
  55. markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
  56. htmlText = StringUtils.breakLinesForHtml(markdownText);
  57. }
  58. // Add the html to the page
  59. add(new Label("markdownText", htmlText).setEscapeModelStrings(false));
  60. }
  61. @Override
  62. protected String getPageName() {
  63. return getString("gb.markdown");
  64. }
  65. @Override
  66. protected Class<? extends BasePage> getRepoNavPageClass() {
  67. return DocsPage.class;
  68. }
  69. }