Search in sources :

Example 1 with RefImageNode

use of org.pegdown.ast.RefImageNode in project gitblit by gitblit.

the class MarkupProcessor method parse.

/**
	 * Parses the document as Markdown using Pegdown.
	 *
	 * @param doc
	 * @param repositoryName
	 * @param commitId
	 */
private void parse(final MarkupDocument doc, final String repositoryName, final String commitId) {
    LinkRenderer renderer = new LinkRenderer() {

        @Override
        public Rendering render(ExpImageNode node, String text) {
            if (node.url.indexOf("://") == -1) {
                // repository-relative image link
                String path = doc.getRelativePath(node.url);
                String contextUrl = RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot();
                String url = RawServlet.asLink(contextUrl, repositoryName, commitId, path);
                return new Rendering(url, text);
            }
            // absolute image link
            return new Rendering(node.url, text);
        }

        @Override
        public Rendering render(RefImageNode node, String url, String title, String alt) {
            Rendering rendering;
            if (url.indexOf("://") == -1) {
                // repository-relative image link
                String path = doc.getRelativePath(url);
                String contextUrl = RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot();
                String wurl = RawServlet.asLink(contextUrl, repositoryName, commitId, path);
                rendering = new Rendering(wurl, alt);
            } else {
                // absolute image link
                rendering = new Rendering(url, alt);
            }
            return StringUtils.isEmpty(title) ? rendering : rendering.withAttribute("title", encode(title));
        }

        @Override
        public Rendering render(WikiLinkNode node) {
            String path = doc.getRelativePath(node.getText());
            String name = getDocumentName(path);
            String url = getWicketUrl(DocPage.class, repositoryName, commitId, path);
            return new Rendering(url, name);
        }
    };
    final String content = MarkdownUtils.transformMarkdown(doc.markup, renderer);
    final String safeContent = xssFilter.relaxed(content);
    doc.html = safeContent;
}
Also used : LinkRenderer(org.pegdown.LinkRenderer) RefImageNode(org.pegdown.ast.RefImageNode) WikiLinkNode(org.pegdown.ast.WikiLinkNode) ExpImageNode(org.pegdown.ast.ExpImageNode)

Aggregations

LinkRenderer (org.pegdown.LinkRenderer)1 ExpImageNode (org.pegdown.ast.ExpImageNode)1 RefImageNode (org.pegdown.ast.RefImageNode)1 WikiLinkNode (org.pegdown.ast.WikiLinkNode)1