Search in sources :

Example 1 with Mention

use of edu.stanford.bmir.protege.web.shared.issues.Mention 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)

Aggregations

Mention (edu.stanford.bmir.protege.web.shared.issues.Mention)1 ParsedMention (edu.stanford.bmir.protege.web.shared.issues.mention.ParsedMention)1 LinkRenderer (org.pegdown.LinkRenderer)1 PegDownProcessor (org.pegdown.PegDownProcessor)1