use of org.commonmark.node.Node in project gitiles by GerritCodeReview.
the class SmartQuotedExtension method quote.
private static void quote(Type type, Text opener, Text closer) {
SmartQuoted quote = new SmartQuoted();
quote.setType(type);
for (Node t = opener.getNext(); t != null && t != closer; ) {
Node next = t.getNext();
quote.appendChild(t);
t = next;
}
opener.insertAfter(quote);
}
use of org.commonmark.node.Node 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>";
}
}
use of org.commonmark.node.Node 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));
}
use of org.commonmark.node.Node 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;
}
use of org.commonmark.node.Node in project toolkit by googleapis.
the class ErrorMarkdownVisitor method visitChildren.
protected void visitChildren(Node node) {
Node child = node.getFirstChild();
while (child != null) {
Node next = child.getNext();
child.accept(this);
child = next;
}
}
Aggregations