Search in sources :

Example 1 with PegDownProcessor

use of org.pegdown.PegDownProcessor in project solo by b3log.

the class Markdowns method toHTML.

/**
     * Converts the specified markdown text to HTML.
     *
     * @param markdownText the specified markdown text
     * @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null}, returns
     * "Markdown error" if exception
     */
public static String toHTML(final String markdownText) {
    if (Strings.isEmptyOrNull(markdownText)) {
        return "";
    }
    final PegDownProcessor pegDownProcessor = new PegDownProcessor(Extensions.ALL_OPTIONALS | Extensions.ALL_WITH_OPTIONALS, 5000);
    String ret = pegDownProcessor.markdownToHtml(markdownText);
    if (!StringUtils.startsWith(ret, "<p>")) {
        ret = "<p>" + ret + "</p>";
    }
    return ret;
}
Also used : PegDownProcessor(org.pegdown.PegDownProcessor)

Example 2 with PegDownProcessor

use of org.pegdown.PegDownProcessor in project activityinfo by bedatadriven.

the class DocGenerator method renderTopics.

private static String renderTopics() throws IOException {
    File contentDir = new File("clients/docs/src/main/content");
    if (!contentDir.exists()) {
        throw new RuntimeException("Content directory does not exist: " + contentDir.getAbsolutePath());
    }
    List<File> files = Arrays.asList(contentDir.listFiles());
    Collections.sort(files, new Comparator<File>() {

        @Override
        public int compare(File o1, File o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    StringBuilder html = new StringBuilder();
    for (File file : files) {
        PegDownProcessor processor = new PegDownProcessor(Extensions.TABLES);
        RootNode rootNode = processor.parseMarkdown(Files.asCharSource(file, Charsets.UTF_8).read().toCharArray());
        MyHtmlSerializer serializer = new MyHtmlSerializer();
        html.append(serializer.toHtml(rootNode));
    }
    return html.toString();
}
Also used : RootNode(org.pegdown.ast.RootNode) PegDownProcessor(org.pegdown.PegDownProcessor) File(java.io.File)

Example 3 with PegDownProcessor

use of org.pegdown.PegDownProcessor in project webprotege by protegeproject.

the class CommentRenderer method renderComment.

public String renderComment(String commentBody) {
    List<ParsedMention> parsedMentions = mentionParser.parseMentions(commentBody);
    StringBuilder rendering = new StringBuilder();
    int currentPos = 0;
    for (ParsedMention pm : parsedMentions) {
        int startIndex = pm.getStartIndex();
        int endIndex = pm.getEndIndex();
        rendering.append(commentBody.substring(currentPos, startIndex));
        Mention mention = pm.getParsedMention();
        if (mention.getMentionedUserId().isPresent()) {
            rendering.append("<span class=\"wp-comment__user-mention\">");
            rendering.append(mention.getMentionedUserId().get().getUserName());
            rendering.append("</span>");
        } else {
            rendering.append(commentBody.substring(startIndex, endIndex));
        }
        currentPos = endIndex;
    }
    if (currentPos < commentBody.length()) {
        rendering.append(commentBody.substring(currentPos));
    }
    PegDownProcessor processor = new PegDownProcessor(Extensions.ABBREVIATIONS | Extensions.QUOTES | Extensions.STRIKETHROUGH | Extensions.AUTOLINKS | Extensions.FENCED_CODE_BLOCKS, new PegDownPlugins.Builder().build());
    String html = processor.markdownToHtml(rendering.toString(), new LinkRenderer() {
    });
    return html;
}
Also used : LinkRenderer(org.pegdown.LinkRenderer) ParsedMention(edu.stanford.bmir.protege.web.shared.issues.mention.ParsedMention) Mention(edu.stanford.bmir.protege.web.shared.issues.Mention) ParsedMention(edu.stanford.bmir.protege.web.shared.issues.mention.ParsedMention) PegDownProcessor(org.pegdown.PegDownProcessor)

Example 4 with PegDownProcessor

use of org.pegdown.PegDownProcessor in project flexmark-java by vsch.

the class PegdownParser method parse.

@Override
public Node parse(BasedSequence input) {
    // here we make the lexer parse the input sequence from start to finish and accumulate everything in custom nodes
    final int pegdownExtensions = getPegdownExtensions(getOptions());
    RootNode rootNode = new PegDownProcessor(pegdownExtensions).parseMarkdown(input.toString().toCharArray());
    return new PegdownRootNode(rootNode);
}
Also used : RootNode(org.pegdown.ast.RootNode) PegDownProcessor(org.pegdown.PegDownProcessor)

Example 5 with PegDownProcessor

use of org.pegdown.PegDownProcessor in project gitblit by gitblit.

the class MarkdownUtils method transformMarkdown.

/**
	 * Returns the html version of the markdown source text.
	 *
	 * @param markdown
	 * @return html version of markdown text
	 * @throws java.text.ParseException
	 */
public static String transformMarkdown(String markdown, LinkRenderer linkRenderer) {
    try {
        PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS & ~ANCHORLINKS);
        RootNode astRoot = pd.parseMarkdown(markdown.toCharArray());
        return new WorkaroundHtmlSerializer(linkRenderer == null ? new LinkRenderer() : linkRenderer).toHtml(astRoot);
    } catch (ParsingTimeoutException e) {
        return null;
    }
}
Also used : RootNode(org.pegdown.ast.RootNode) LinkRenderer(org.pegdown.LinkRenderer) WorkaroundHtmlSerializer(com.gitblit.wicket.MarkupProcessor.WorkaroundHtmlSerializer) ParsingTimeoutException(org.pegdown.ParsingTimeoutException) PegDownProcessor(org.pegdown.PegDownProcessor)

Aggregations

PegDownProcessor (org.pegdown.PegDownProcessor)6 RootNode (org.pegdown.ast.RootNode)3 LinkRenderer (org.pegdown.LinkRenderer)2 WorkaroundHtmlSerializer (com.gitblit.wicket.MarkupProcessor.WorkaroundHtmlSerializer)1 Vertex (com.tinkerpop.blueprints.Vertex)1 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)1 PopoverConfig (de.agilecoders.wicket.core.markup.html.bootstrap.components.PopoverConfig)1 Mention (edu.stanford.bmir.protege.web.shared.issues.Mention)1 ParsedMention (edu.stanford.bmir.protege.web.shared.issues.mention.ParsedMention)1 Template (eu.esdihumboldt.hale.server.model.Template)1 User (eu.esdihumboldt.hale.server.model.User)1 DeleteTemplateLink (eu.esdihumboldt.hale.server.templates.war.components.DeleteTemplateLink)1 ProjectURLPopover (eu.esdihumboldt.hale.server.templates.war.components.ProjectURLPopover)1 ResourcesPanel (eu.esdihumboldt.hale.server.templates.war.components.ResourcesPanel)1 HTMLPopoverBehavior (eu.esdihumboldt.hale.server.webapp.components.bootstrap.HTMLPopoverBehavior)1 NonUniqueResultException (eu.esdihumboldt.util.blueprints.entities.NonUniqueResultException)1 File (java.io.File)1 Component (org.apache.wicket.Component)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 Label (org.apache.wicket.markup.html.basic.Label)1