Search in sources :

Example 1 with ExpImageNode

use of org.pegdown.ast.ExpImageNode in project zeppelin by apache.

the class PegdownWebSequencelPlugin method BlockRule.

Rule BlockRule() {
    StringBuilderVar style = new StringBuilderVar();
    StringBuilderVar body = new StringBuilderVar();
    return NodeSequence(StartMarker(), Optional(String("style="), Sequence(OneOrMore(Letter()), style.append(match()), Spn1())), Sequence(Body(), body.append(match())), EndMarker(), push(new ExpImageNode("title", createWebsequenceUrl(style.getString(), body.getString()), new TextNode(""))));
}
Also used : StringBuilderVar(org.parboiled.support.StringBuilderVar) TextNode(org.pegdown.ast.TextNode) ExpImageNode(org.pegdown.ast.ExpImageNode)

Example 2 with ExpImageNode

use of org.pegdown.ast.ExpImageNode in project zeppelin by apache.

the class PegdownYumlPlugin method BlockRule.

Rule BlockRule() {
    ParamVar<String, String> params = new ParamVar<String, String>();
    StringBuilderVar name = new StringBuilderVar();
    StringBuilderVar value = new StringBuilderVar();
    StringBuilderVar body = new StringBuilderVar();
    return NodeSequence(StartMarker(), ZeroOrMore(Sequence(ParameterName(), name.append(match()), String("="), OneOrMore(Alphanumeric()), value.append(match())), Sp(), params.put(name.getString(), value.getString()), name.clear(), value.clear()), Body(), body.append(match()), EndMarker(), push(new ExpImageNode("title", createYumlUrl(params.get(), body.getString()), new TextNode(""))));
}
Also used : StringBuilderVar(org.parboiled.support.StringBuilderVar) TextNode(org.pegdown.ast.TextNode) StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString) ExpImageNode(org.pegdown.ast.ExpImageNode)

Example 3 with ExpImageNode

use of org.pegdown.ast.ExpImageNode 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

ExpImageNode (org.pegdown.ast.ExpImageNode)3 StringBuilderVar (org.parboiled.support.StringBuilderVar)2 TextNode (org.pegdown.ast.TextNode)2 StringUtils.defaultString (org.apache.commons.lang3.StringUtils.defaultString)1 LinkRenderer (org.pegdown.LinkRenderer)1 RefImageNode (org.pegdown.ast.RefImageNode)1 WikiLinkNode (org.pegdown.ast.WikiLinkNode)1