Search in sources :

Example 6 with HtmlRenderer

use of org.commonmark.renderer.html.HtmlRenderer in project lavagna by digitalfondue.

the class MailTicketService method sendEmail.

private void sendEmail(String to, String name, Card createdCard, Board board, ProjectMailTicketConfig config, ProjectMailTicket ticketConfig) {
    String cardId = board.getShortName() + "-" + createdCard.getSequence();
    String subjectTemplate = "" + (ticketConfig.getNotificationOverride() ? ticketConfig.getSubject() : config.getSubject());
    String bodyTemplate = "" + (ticketConfig.getNotificationOverride() ? ticketConfig.getBody() : config.getBody());
    String subject = subjectTemplate.replaceAll("\\{\\{card}}", cardId);
    String body = bodyTemplate.replaceAll("\\{\\{card}}", cardId).replaceAll("\\{\\{name}}", name != null ? name : to);
    Parser parser = Parser.builder().build();
    Node document = parser.parse(body);
    HtmlRenderer htmlRenderer = HtmlRenderer.builder().build();
    TextContentRenderer textRendered = TextContentRenderer.builder().build();
    String htmlText = htmlRenderer.render(document);
    String plainText = textRendered.render(document);
    ProjectMailTicketConfigData configData = config.getConfig();
    MailConfig mailConfig = new MailConfig(configData.getOutboundServer(), configData.getOutboundPort(), configData.getOutboundProtocol(), configData.getOutboundUser(), configData.getOutboundPassword(), ticketConfig.getSendByAlias() ? ticketConfig.getAlias() : configData.getOutboundAddress(), configData.getOutboundProperties());
    mailConfig.send(to, subject, plainText, htmlText);
}
Also used : Node(org.commonmark.node.Node) TextContentRenderer(org.commonmark.renderer.text.TextContentRenderer) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Example 7 with HtmlRenderer

use of org.commonmark.renderer.html.HtmlRenderer in project mdw-designer by CenturyLinkCloud.

the class MarkdownRenderer method renderHtml.

public String renderHtml() {
    if (markdown == null || markdown.trim().isEmpty())
        return "";
    else {
        Parser parser = Parser.builder().build();
        Node document = parser.parse(markdown);
        HtmlRenderer renderer = HtmlRenderer.builder().build();
        return "<div style=\"height:100%;overflow:auto;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif\">" + renderer.render(document) + "</div>";
    }
}
Also used : Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Example 8 with HtmlRenderer

use of org.commonmark.renderer.html.HtmlRenderer in project MagiskManager by topjohnwu.

the class MarkDownWindow method doInBackground.

@Override
protected String doInBackground(Void... voids) {
    MagiskManager mm = MagiskManager.get();
    String md;
    if (mUrl != null) {
        md = WebService.getString(mUrl);
    } else {
        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            ShellUtils.pump(is, out);
            md = out.toString();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
    String css;
    try (InputStream in = mm.getResources().openRawResource(mm.isDarkTheme ? R.raw.dark : R.raw.light);
        ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        ShellUtils.pump(in, out);
        css = out.toString();
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
    Parser parser = Parser.builder().build();
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    Node doc = parser.parse(md);
    return String.format("<style>%s</style>%s", css, renderer.render(doc));
}
Also used : MagiskManager(com.topjohnwu.magisk.MagiskManager) InputStream(java.io.InputStream) Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Parser(org.commonmark.parser.Parser)

Example 9 with HtmlRenderer

use of org.commonmark.renderer.html.HtmlRenderer in project tale by otale.

the class TaleUtils method mdToHtml.

/**
 * markdown转换为html
 */
public static String mdToHtml(String markdown) {
    if (StringKit.isBlank(markdown)) {
        return "";
    }
    List<Extension> extensions = Collections.singletonList(TablesExtension.create());
    Parser parser = Parser.builder().extensions(extensions).build();
    Node document = parser.parse(markdown);
    HtmlRenderer renderer = HtmlRenderer.builder().attributeProviderFactory(context -> new LinkAttributeProvider()).extensions(extensions).build();
    String content = renderer.render(document);
    content = Commons.emoji(content);
    // 支持网易云音乐输出
    if (TaleConst.BCONF.getBoolean(ENV_SUPPORT_163_MUSIC, true) && content.contains(MP3_PREFIX)) {
        content = content.replaceAll(MUSIC_REG_PATTERN, MUSIC_IFRAME);
    }
    // 支持gist代码输出
    if (TaleConst.BCONF.getBoolean(ENV_SUPPORT_GIST, true) && content.contains(GIST_PREFIX_URL)) {
        content = content.replaceAll(GIST_REG_PATTERN, GIST_REPLATE_PATTERN);
    }
    return content;
}
Also used : Extension(org.commonmark.Extension) TablesExtension(org.commonmark.ext.gfm.tables.TablesExtension) Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Example 10 with HtmlRenderer

use of org.commonmark.renderer.html.HtmlRenderer in project TOSCAna by StuPro-TOSCAna.

the class ReadmeBuilder method toString.

@Override
public String toString() {
    Parser markdownParser = Parser.builder().build();
    Node markdownDocument = markdownParser.parse(this.markdownText);
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    return TEMPLATE.replace(README_TEMPLATE_TITLE_KEY, this.pageTitle).replace(README_TEMPLATE_BODY_KEY, renderer.render(markdownDocument));
}
Also used : Node(org.commonmark.node.Node) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Aggregations

Parser (org.commonmark.parser.Parser)13 HtmlRenderer (org.commonmark.renderer.html.HtmlRenderer)13 Node (org.commonmark.node.Node)12 Extension (org.commonmark.Extension)5 TablesExtension (org.commonmark.ext.gfm.tables.TablesExtension)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 AppWidgetManager (android.appwidget.AppWidgetManager)1 ComponentName (android.content.ComponentName)1 SharedPreferences (android.content.SharedPreferences)1 RemoteViews (android.widget.RemoteViews)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 MagiskManager (com.topjohnwu.magisk.MagiskManager)1 EmojiParser (com.vdurmont.emoji.EmojiParser)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1