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;
}
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();
}
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;
}
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);
}
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;
}
}
Aggregations